Documentation ¶
Overview ¶
Package stringenumer generate useful code for enums defined as strings
type MyEnum string const ( MyEnumThis MyEnum = "this" MyEnumThat MyEnum = "that" )
The code that is generated by default is a Valid function:
func (e MyEnum) Valid() bool
It can also generate an TextUnmarshaling function for the type that validates any string that is unmarshaled into this type. Via, for example, json.Unmarshal.
Example ¶
package main import ( "io" "log" "os" "github.com/lindell/string-enumer/pkg/stringenumer" ) func main() { r, err := stringenumer.Generate( stringenumer.Paths("."), stringenumer.TypeNames("MyType", "YourType"), stringenumer.TextUnmarshaling(true), ) if err != nil { log.Fatalln(err) } _, _ = io.Copy(os.Stdout, r) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.