forked from ebhomengo/niki
45 lines
921 B
Go
45 lines
921 B
Go
package entity
|
|
|
|
type AdminRole uint
|
|
|
|
const (
|
|
AdminSuperAdminRole AdminRole = iota + 1
|
|
AdminAdminRole
|
|
AdminAgentRole
|
|
)
|
|
|
|
var AdminRoleStrings = map[AdminRole]string{
|
|
AdminSuperAdminRole: "super-admin",
|
|
AdminAdminRole: "admin",
|
|
AdminAgentRole: "agent",
|
|
}
|
|
|
|
func (s AdminRole) String() string {
|
|
return AdminRoleStrings[s]
|
|
}
|
|
|
|
func (s AdminRole) IsValid() bool {
|
|
return s > 0 && int(s) <= len(AdminRoleStrings)
|
|
}
|
|
|
|
// AllAdminRole returns a slice containing all string values of AdminRole.
|
|
func AllAdminRole() []string {
|
|
roleStrings := make([]string, len(AdminRoleStrings))
|
|
for role, str := range AdminRoleStrings {
|
|
roleStrings[int(role)-1] = str
|
|
}
|
|
|
|
return roleStrings
|
|
}
|
|
|
|
// MapToAdminRole converts a string to the corresponding AdminRole value.
|
|
func MapToAdminRole(roleStr string) AdminRole {
|
|
for role, str := range AdminRoleStrings {
|
|
if str == roleStr {
|
|
return role
|
|
}
|
|
}
|
|
|
|
return AdminRole(0)
|
|
}
|