2024-01-05 12:13:47 +00:00
|
|
|
package entity
|
|
|
|
|
|
|
|
type AdminRole uint
|
|
|
|
|
|
|
|
const (
|
2024-03-14 13:38:42 +00:00
|
|
|
AdminSuperAdminRole AdminRole = iota + 1
|
|
|
|
AdminAdminRole
|
|
|
|
AdminAgentRole
|
2024-01-05 12:13:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var AdminRoleStrings = map[AdminRole]string{
|
|
|
|
AdminSuperAdminRole: "super-admin",
|
2024-03-14 13:38:42 +00:00
|
|
|
AdminAdminRole: "admin",
|
|
|
|
AdminAgentRole: "agent",
|
2024-01-05 12:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s AdminRole) String() string {
|
|
|
|
return AdminRoleStrings[s]
|
|
|
|
}
|
|
|
|
|
2024-01-19 16:56:11 +00:00
|
|
|
func (s AdminRole) IsValid() bool {
|
|
|
|
return s > 0 && int(s) <= len(AdminRoleStrings)
|
|
|
|
}
|
|
|
|
|
2024-01-05 12:13:47 +00:00
|
|
|
// 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)
|
|
|
|
}
|