forked from ebhomengo/niki
39 lines
806 B
Go
39 lines
806 B
Go
|
package entity
|
||
|
|
||
|
type UserGender uint
|
||
|
|
||
|
const (
|
||
|
UserMaleGender UserGender = iota + 1
|
||
|
UserFemaleGender
|
||
|
)
|
||
|
|
||
|
var UserGenderStrings = map[UserGender]string{
|
||
|
UserMaleGender: "male",
|
||
|
UserFemaleGender: "female",
|
||
|
}
|
||
|
|
||
|
func (s UserGender) String() string {
|
||
|
return UserGenderStrings[s]
|
||
|
}
|
||
|
|
||
|
// AllUserGender returns a slice containing all string values of UserGender.
|
||
|
func AllUserGender() []string {
|
||
|
statusStrings := make([]string, len(UserGenderStrings))
|
||
|
for status, str := range UserGenderStrings {
|
||
|
statusStrings[int(status)-1] = str
|
||
|
}
|
||
|
|
||
|
return statusStrings
|
||
|
}
|
||
|
|
||
|
// MapToUserGender converts a string to the corresponding UserGender value.
|
||
|
func MapToUserGender(statusStr string) UserGender {
|
||
|
for status, str := range UserGenderStrings {
|
||
|
if str == statusStr {
|
||
|
return status
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return UserGender(0)
|
||
|
}
|