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

43 lines
804 B
Go
Raw Normal View History

package entity
type Gender uint
const (
MaleGender Gender = iota + 1
FemaleGender
)
var GenderStrings = map[Gender]string{
MaleGender: "male",
FemaleGender: "female",
}
func (s Gender) String() string {
return GenderStrings[s]
}
// AllGender returns a slice containing all string values of Gender.
func AllGender() []string {
statusStrings := make([]string, len(GenderStrings))
for status, str := range GenderStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
func (s Gender) IsValid() bool {
return s > 0 && int(s) <= len(GenderStrings)
}
// MapToGender converts a string to the corresponding Gender value.
func MapToGender(statusStr string) Gender {
for status, str := range GenderStrings {
if str == statusStr {
return status
}
}
return Gender(0)
}