github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/app/lib/schema/model/modeltype.go (about) 1 // Package model - Content managed by Project Forge, see [projectforge.md] for details. 2 package model 3 4 type Type struct { 5 Key string 6 Title string 7 Plural string 8 Icon string 9 } 10 11 var ( 12 TypeEnum = Type{Key: "enum", Title: "Enum", Plural: "Enums", Icon: "list"} 13 TypeStruct = Type{Key: "struct", Title: "Struct", Plural: "Structs", Icon: "struct"} 14 TypeInterface = Type{Key: "interface", Title: "Interface", Plural: "Interfaces", Icon: "list"} 15 TypeUnion = Type{Key: "union", Title: "Union", Plural: "Unions", Icon: "world"} 16 TypeIntersection = Type{Key: "intersection", Title: "Intersection", Plural: "Intersections", Icon: "world"} 17 TypeUnknown = Type{Key: "unknown", Title: "Unknown", Plural: "Unknowns", Icon: "world"} 18 ) 19 20 var AllModelTypes = []Type{TypeEnum, TypeStruct, TypeInterface, TypeUnion, TypeIntersection, TypeUnknown} 21 22 func modelTypeFromString(s string) (Type, error) { 23 for _, t := range AllModelTypes { 24 if t.Key == s { 25 return t, nil 26 } 27 } 28 return TypeUnknown, nil 29 } 30 31 func (t *Type) String() string { 32 return t.Key 33 } 34 35 func (t *Type) MarshalText() ([]byte, error) { 36 return []byte(t.Key), nil 37 } 38 39 func (t *Type) UnmarshalText(data []byte) error { 40 x, err := modelTypeFromString(string(data)) 41 if err != nil { 42 return err 43 } 44 *t = x 45 return nil 46 }