Documentation
¶
Index ¶
- func DirectValue(enumType string, val EnumValue) (strResult string)
- func Mapify(e Enum) (ret string, err error)
- func Namify(e Enum) (ret string, err error)
- func Offset(index int, enumType string, val EnumValue) (strResult string)
- func ParseAliases(aliases []string) (map[string]string, error)
- func Stringify(e Enum, forceLower, forceUpper bool) (ret string, err error)
- func Unmapify(e Enum, lowercase bool) (ret string, err error)
- func UnmapifyStringEnum(e Enum, lowercase bool) (ret string, err error)
- type Enum
- type EnumValue
- type Generator
- type GeneratorConfig
- type Option
- func WithAliases(aliases map[string]string) Option
- func WithBuildTags(tags ...string) Option
- func WithCaseInsensitiveParse() Option
- func WithFlag() Option
- func WithForceLower() Option
- func WithForceUpper() Option
- func WithJsonPkg(pkg string) Option
- func WithLowercaseVariant() Option
- func WithMarshal() Option
- func WithMustParse() Option
- func WithNames() Option
- func WithNoComments() Option
- func WithNoIota() Option
- func WithNoPrefix() Option
- func WithPrefix(prefix string) Option
- func WithPtr() Option
- func WithSQLDriver() Option
- func WithSQLInt() Option
- func WithSQLNullInt() Option
- func WithSQLNullStr() Option
- func WithTemplates(filenames ...string) Option
- func WithValues() Option
- func WithoutSnakeToCamel() Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DirectValue ¶ added in v0.9.0
DirectValue returns the exact value of the enum, not adjusted for iota at all.
func Namify ¶ added in v0.1.4
Namify returns a slice that is all of the possible names for an enum in a slice
func ParseAliases ¶ added in v0.3.8
ParseAliases is used to add aliases to replace during name sanitization.
func Stringify ¶
Stringify returns a string that is all of the enum value names concatenated without a separator
Types ¶
type EnumValue ¶
type EnumValue struct { RawName string Name string PrefixedName string ValueStr string ValueInt any Comment string }
EnumValue holds the individual data for each enum value within the found enum.
type Generator ¶
type Generator struct { Version string Revision string BuildDate string BuiltBy string GeneratorConfig // contains filtered or unexported fields }
Generator is responsible for generating validation files for the given in a go source file.
func NewGenerator ¶
NewGenerator is a constructor method for creating a new Generator with default templates loaded.
func NewGeneratorWithConfig ¶ added in v0.8.0
func NewGeneratorWithConfig(config GeneratorConfig) *Generator
NewGeneratorWithConfig is a constructor method for creating a new Generator with a configuration struct instead of using the functional options pattern.
func (*Generator) Generate ¶
Generate does the heavy lifting for the code generation starting from the parsed AST file.
func (*Generator) GenerateFromFile ¶
GenerateFromFile is responsible for orchestrating the Code generation. It results in a byte array that can be written to any file desired. It has already had goimports run on the code before being returned.
type GeneratorConfig ¶ added in v0.8.0
type GeneratorConfig struct { NoPrefix bool `json:"no_prefix"` NoIota bool `json:"no_iota"` LowercaseLookup bool `json:"lowercase_lookup"` CaseInsensitive bool `json:"case_insensitive"` Marshal bool `json:"marshal"` SQL bool `json:"sql"` SQLInt bool `json:"sql_int"` Flag bool `json:"flag"` Names bool `json:"names"` Values bool `json:"values"` LeaveSnakeCase bool `json:"leave_snake_case"` JSONPkg string `json:"json_pkg"` Prefix string `json:"prefix"` SQLNullInt bool `json:"sql_null_int"` SQLNullStr bool `json:"sql_null_str"` Ptr bool `json:"ptr"` MustParse bool `json:"must_parse"` ForceLower bool `json:"force_lower"` ForceUpper bool `json:"force_upper"` NoComments bool `json:"no_comments"` BuildTags []string `json:"build_tags"` ReplacementNames map[string]string `json:"replacement_names"` TemplateFileNames []string `json:"template_file_names"` }
GeneratorConfig holds all the configuration options for the Generator
func NewGeneratorConfig ¶ added in v0.8.0
func NewGeneratorConfig() *GeneratorConfig
type Option ¶ added in v0.8.0
type Option func(*GeneratorConfig)
Option is a function that modifies a Generator
func WithAliases ¶ added in v0.8.0
WithAliases will set up aliases for the generator.
func WithBuildTags ¶ added in v0.8.0
WithBuildTags will add build tags to the generated file.
func WithCaseInsensitiveParse ¶ added in v0.8.0
func WithCaseInsensitiveParse() Option
WithCaseInsensitiveParse is used to change the enum const values generated to not have the enum on them.
func WithFlag ¶ added in v0.8.0
func WithFlag() Option
WithFlag is used to add flag methods to the enum
func WithForceLower ¶ added in v0.8.0
func WithForceLower() Option
WithForceLower is used to force enums names to lower case while keeping variable names the same.
func WithForceUpper ¶ added in v0.8.0
func WithForceUpper() Option
WithForceUpper is used to force enums names to upper case while keeping variable names the same.
func WithJsonPkg ¶ added in v0.8.0
WithJsonPkg is used to add a custom json package to the imports
func WithLowercaseVariant ¶ added in v0.8.0
func WithLowercaseVariant() Option
WithLowercaseVariant is used to change the enum const values generated to not have the enum on them.
func WithMarshal ¶ added in v0.8.0
func WithMarshal() Option
WithMarshal is used to add marshalling to the enum
func WithMustParse ¶ added in v0.8.0
func WithMustParse() Option
WithMustParse is used to add a method `MustParse` that will panic on failure.
func WithNames ¶ added in v0.8.0
func WithNames() Option
WithNames is used to add Names methods to the enum
func WithNoComments ¶ added in v0.8.0
func WithNoComments() Option
WithNoComments is used to remove auto generated comments from the enum.
func WithNoIota ¶ added in v0.9.0
func WithNoIota() Option
WithNoIota is used to generate enum constants with explicit values instead of using iota.
func WithNoPrefix ¶ added in v0.8.0
func WithNoPrefix() Option
WithNoPrefix is used to change the enum const values generated to not have the enum on them.
func WithPrefix ¶ added in v0.8.0
WithPrefix is used to add a custom prefix to the enum constants
func WithPtr ¶ added in v0.8.0
func WithPtr() Option
WithPtr adds a way to get a pointer value straight from the const value.
func WithSQLDriver ¶ added in v0.8.0
func WithSQLDriver() Option
WithSQLDriver is used to add marshalling to the enum
func WithSQLInt ¶ added in v0.8.0
func WithSQLInt() Option
WithSQLInt is used to signal a string to be stored as an int.
func WithSQLNullInt ¶ added in v0.8.0
func WithSQLNullInt() Option
WithSQLNullInt is used to add a null int option for SQL interactions.
func WithSQLNullStr ¶ added in v0.8.0
func WithSQLNullStr() Option
WithSQLNullStr is used to add a null string option for SQL interactions.
func WithTemplates ¶ added in v0.8.0
WithTemplates is used to provide the filenames of additional templates.
func WithValues ¶ added in v0.8.0
func WithValues() Option
WithValues is used to add Values methods to the enum
func WithoutSnakeToCamel ¶ added in v0.8.0
func WithoutSnakeToCamel() Option
WithoutSnakeToCamel is used to add flag methods to the enum