niki/entity/admin_role.go

39 lines
786 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]
}
// 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)
}