Auto generate your types and implement various interfaces by only creating
constants. All you need to do is add a go generate
line above your constant
group.
//go:generate go-enum --trim "Post" --format snake
const (
PostCreate PostType = 0
PostRead PostType = 2
PostUpdate PostType = 4
PostDelete PostType = 8
)
See the example folder for example generated code.
go get -u https://github.com/bombsimon/enum/...
The current interfaces that will be implemented are
FromString
- Convert a string to the enum typeString
- Get the string value for the enumValid
- Returns true or false if the enum is validMarshalJSON
- JSON marshal interfaceUnmarshalJSON
- JSON unmarshal interface