forked from ebhomengo/niki
1
0
Fork 0
niki/entity/admin_role.go

43 lines
874 B
Go

package entity
type AdminRole uint
const (
AdminAdminRole AdminRole = iota + 1
AdminSuperAdminRole
)
var AdminRoleStrings = map[AdminRole]string{
AdminAdminRole: "admin",
AdminSuperAdminRole: "super-admin",
}
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)
}