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

35 lines
658 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)
}
// 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)
}