4 ms·
I use this one https://github.com/abice/go-enum https://github.com/abice/go-enum
by kleton 3y ago
I use this one https://github.com/abice/go-enum https://github.com/abice/go-enum
- lantastic 3y agoI like the "go generate" approach to integrate such tools. I used a different (but identically named) go-enum tool [0], which accepts the go type and generates implementations for a bunch of interfaces. The neat thing is that the starting point is the "idiomatic" go enum definition, rather than description via a separate DSL: //go:generate go-enum -type=State type State int const ( Unknown State = 0 Disconnected = 1 Connected = 2 ) which then generates a separate file with implementations such as: func (i State) MarshalJSON() ([]byte, error) { ... [0] https://pkg.go.dev/github.com/searKing/golang/tools/go-enum#section-readme https://pkg.go.dev/github.com/searKing/golang/tools/go-enum#...