Documentation ¶
Overview ¶
Enumer is a tool to automate the creation of methods that satisfy the jsonschema.Enum (https://pkg.go.dev/github.com/swaggest/jsonschema-go#Enum) interface.
For example, given this snippet,
package painkiller type Pill int const ( Placebo Pill = iota Aspirin Ibuprofen Paracetamol Acetaminophen = Paracetamol )
running this command
enumer -type=Pill
in the same directory will create the file pill_enum.go, in package painkiller, containing a definition of
func (Pill) Enum() []interface{}
Typically this process would be run using go generate, like this:
//go:generate enumer -type=Pill
With no arguments, it processes the package in the current directory. Otherwise, the arguments must name a single directory holding a Go package or a set of Go source files that represent a single Go package.
The -type flag accepts a comma-separated list of types so a single run can generate methods for multiple types. The default output file is t_string.go, where t is the lower-cased name of the first type listed. It can be overridden with the -output flag.
This file originates from https://github.com/golang/tools/blob/master/cmd/stringer/stringer.go.