github.com/octohelm/storage@v0.0.0-20240516030302-1ac2cc1ea347/testdata/model/zz_generated.enum.go (about) 1 /* 2 Package model GENERATED BY gengo:enum 3 DON'T EDIT THIS FILE 4 */ 5 package model 6 7 import ( 8 bytes "bytes" 9 database_sql_driver "database/sql/driver" 10 11 github_com_octohelm_storage_pkg_enumeration "github.com/octohelm/storage/pkg/enumeration" 12 github_com_pkg_errors "github.com/pkg/errors" 13 ) 14 15 var InvalidGender = github_com_pkg_errors.New("invalid Gender") 16 17 func (Gender) EnumValues() []any { 18 return []any{ 19 GENDER__MALE, GENDER__FEMALE, 20 } 21 } 22 func (v Gender) MarshalText() ([]byte, error) { 23 str := v.String() 24 if str == "UNKNOWN" { 25 return nil, InvalidGender 26 } 27 return []byte(str), nil 28 } 29 30 func (v *Gender) UnmarshalText(data []byte) error { 31 vv, err := ParseGenderFromString(string(bytes.ToUpper(data))) 32 if err != nil { 33 return err 34 } 35 *v = vv 36 return nil 37 } 38 39 func ParseGenderFromString(s string) (Gender, error) { 40 switch s { 41 case "MALE": 42 return GENDER__MALE, nil 43 case "FEMALE": 44 return GENDER__FEMALE, nil 45 46 default: 47 return GENDER_UNKNOWN, InvalidGender 48 } 49 } 50 51 func (v Gender) String() string { 52 switch v { 53 case GENDER__MALE: 54 return "MALE" 55 case GENDER__FEMALE: 56 return "FEMALE" 57 58 default: 59 return "UNKNOWN" 60 } 61 } 62 63 func ParseGenderLabelString(label string) (Gender, error) { 64 switch label { 65 case "男": 66 return GENDER__MALE, nil 67 case "女": 68 return GENDER__FEMALE, nil 69 70 default: 71 return GENDER_UNKNOWN, InvalidGender 72 } 73 } 74 75 func (v Gender) Label() string { 76 switch v { 77 case GENDER__MALE: 78 return "男" 79 case GENDER__FEMALE: 80 return "女" 81 82 default: 83 return "UNKNOWN" 84 } 85 } 86 87 func (v Gender) Value() (database_sql_driver.Value, error) { 88 offset := 0 89 if o, ok := any(v).(github_com_octohelm_storage_pkg_enumeration.DriverValueOffset); ok { 90 offset = o.Offset() 91 } 92 return int64(v) + int64(offset), nil 93 } 94 95 func (v *Gender) Scan(src any) error { 96 offset := 0 97 if o, ok := any(v).(github_com_octohelm_storage_pkg_enumeration.DriverValueOffset); ok { 98 offset = o.Offset() 99 } 100 101 i, err := github_com_octohelm_storage_pkg_enumeration.ScanIntEnumStringer(src, offset) 102 if err != nil { 103 return err 104 } 105 *v = Gender(i) 106 return nil 107 } 108 109 var InvalidGenderExt = github_com_pkg_errors.New("invalid GenderExt") 110 111 func (GenderExt) EnumValues() []any { 112 return []any{ 113 GENDER_EXT__FEMALE, GENDER_EXT__MALE, 114 } 115 } 116 func ParseGenderExtLabelString(label string) (GenderExt, error) { 117 switch label { 118 case "女": 119 return GENDER_EXT__FEMALE, nil 120 case "男": 121 return GENDER_EXT__MALE, nil 122 123 default: 124 return "", InvalidGenderExt 125 } 126 } 127 128 func (v GenderExt) Label() string { 129 switch v { 130 case GENDER_EXT__FEMALE: 131 return "女" 132 case GENDER_EXT__MALE: 133 return "男" 134 135 default: 136 return "UNKNOWN" 137 } 138 }