generator

package
v0.0.0-...-588beaa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mapify

func Mapify(e Enum) (ret string, err error)

Mapify returns a map that is all of the indexes for a string value lookup

func Namify

func Namify(e Enum) (ret string, err error)

Namify returns a slice that is all of the possible names for an enum in a slice

func Offset

func Offset(index int, enumType string, val EnumValue) (strResult string)

func ParseAliases

func ParseAliases(aliases []string) error

ParseAliases is used to add aliases to replace during name sanitization.

func Stringify

func Stringify(e Enum, forceLower bool) (ret string, err error)

Stringify returns a string that is all of the enum value names concatenated without a separator

func Unmapify

func Unmapify(e Enum, lowercase bool) (ret string, err error)

Unmapify returns a map that is all of the indexes for a string value lookup

func UnmapifyStringEnum

func UnmapifyStringEnum(e Enum, lowercase bool) (ret string, err error)

Unmapify returns a map that is all of the indexes for a string value lookup

Types

type Enum

type Enum struct {
	Name   string
	Prefix string
	Type   string
	Values []EnumValue
}

Enum holds data for a discovered enum in the parsed source

type EnumValue

type EnumValue struct {
	RawName      string
	Name         string
	PrefixedName string
	ValueStr     string
	ValueInt     interface{}
	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
	// contains filtered or unexported fields
}

Generator is responsible for generating validation files for the given in a go source file.

func NewGenerator

func NewGenerator() *Generator

NewGenerator is a constructor method for creating a new Generator with default templates loaded.

func (*Generator) Generate

func (g *Generator) Generate(f *ast.File) ([]byte, error)

Generate does the heavy lifting for the code generation starting from the parsed AST file.

func (*Generator) GenerateFromFile

func (g *Generator) GenerateFromFile(inputFile string) ([]byte, error)

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.

func (*Generator) WithBuildTags

func (g *Generator) WithBuildTags(tags ...string) *Generator

WithBuildTags will add build tags to the generated file.

func (*Generator) WithCaseInsensitiveParse

func (g *Generator) WithCaseInsensitiveParse() *Generator

WithLowercaseVariant is used to change the enum const values generated to not have the enum on them.

func (*Generator) WithFlag

func (g *Generator) WithFlag() *Generator

WithFlag is used to add flag methods to the enum

func (*Generator) WithForceLower

func (g *Generator) WithForceLower() *Generator

WithForceLower is used to force enums names to lower case while keeping variable names the same.

func (*Generator) WithLowercaseVariant

func (g *Generator) WithLowercaseVariant() *Generator

WithLowercaseVariant is used to change the enum const values generated to not have the enum on them.

func (*Generator) WithMarshal

func (g *Generator) WithMarshal() *Generator

WithMarshal is used to add marshalling to the enum

func (*Generator) WithMustParse

func (g *Generator) WithMustParse() *Generator

WithMustParse is used to add a method `MustParse` that will panic on failure.

func (*Generator) WithNames

func (g *Generator) WithNames() *Generator

WithNames is used to add Names methods to the enum

func (*Generator) WithNoComments

func (g *Generator) WithNoComments() *Generator

WithNoComments is used to remove auto generated comments from the enum.

func (*Generator) WithNoPrefix

func (g *Generator) WithNoPrefix() *Generator

WithNoPrefix is used to change the enum const values generated to not have the enum on them.

func (*Generator) WithPrefix

func (g *Generator) WithPrefix(prefix string) *Generator

WithPrefix is used to add a custom prefix to the enum constants

func (*Generator) WithPtr

func (g *Generator) WithPtr() *Generator

WithPtr adds a way to get a pointer value straight from the const value.

func (*Generator) WithSQLDriver

func (g *Generator) WithSQLDriver() *Generator

WithSQLDriver is used to add marshalling to the enum

func (*Generator) WithSQLInt

func (g *Generator) WithSQLInt() *Generator

WithSQLInt is used to signal a string to be stored as an int.

func (*Generator) WithSQLNullInt

func (g *Generator) WithSQLNullInt() *Generator

WithSQLNullInt is used to add a null int option for SQL interactions.

func (*Generator) WithSQLNullStr

func (g *Generator) WithSQLNullStr() *Generator

WithSQLNullStr is used to add a null string option for SQL interactions.

func (*Generator) WithTemplates

func (g *Generator) WithTemplates(filenames ...string) *Generator

WithTemplates is used to provide the filenames of additional templates.

func (*Generator) WithValues

func (g *Generator) WithValues() *Generator

WithValues is used to add Values methods to the enum

func (*Generator) WithoutSnakeToCamel

func (g *Generator) WithoutSnakeToCamel() *Generator

WithoutSnakeToCamel is used to add flag methods to the enum

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL