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/mcraq/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)
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*generator)
Option is used in the call of Generate to change the behavior
func TextUnmarshaling ¶
TextUnmarshaling sets if text unarshaling should be generated or not
func TypeDefinition ¶
TypeDefinition sets if the type is a definition
Click to show internal directories.
Click to hide internal directories.