package entity type UserRole uint const ( UserBenefactorRole UserRole = iota + 1 ) var UserRoleStrings = map[UserRole]string{ UserBenefactorRole: "benefactor", } func (s UserRole) String() string { return UserRoleStrings[s] } // AllUserRole returns a slice containing all string values of UserRole. func AllUserRole() []string { roleStrings := make([]string, len(UserRoleStrings)) for role, str := range UserRoleStrings { roleStrings[int(role)-1] = str } return roleStrings } // MapToUserRole converts a string to the corresponding UserRole value. func MapToUserRole(roleStr string) UserRole { for role, str := range UserRoleStrings { if str == roleStr { return role } } return UserRole(0) }