2024-01-05 12:13:47 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-01-19 16:56:11 +00:00
|
|
|
func (s Gender) IsValid() bool {
|
|
|
|
return s > 0 && int(s) <= len(GenderStrings)
|
|
|
|
}
|
|
|
|
|
2024-01-05 12:13:47 +00:00
|
|
|
// 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)
|
|
|
|
}
|