generator

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDigest added in v0.1.3

func AssetDigest(name string) ([sha256.Size]byte, error)

AssetDigest returns the digest of the file with the given name. It returns an error if the asset could not be found or the digest could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"}, AssetDir("data/img") would return []string{"a.png", "b.png"}, AssetDir("foo.txt") and AssetDir("notexist") would return an error, and AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func AssetString added in v0.1.3

func AssetString(name string) (string, error)

AssetString returns the asset contents as a string (instead of a []byte).

func Digests added in v0.1.3

func Digests() (map[string][sha256.Size]byte, error)

Digests returns a map of all known files and their checksums.

func GenerationError

func GenerationError(s string) (ret interface{}, err error)

GenerationError is a helper method for templates to generate an error if something is unsupported.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func MustAssetString added in v0.1.3

func MustAssetString(name string) string

MustAssetString is like AssetString but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory.

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively.

Types

type Field

type Field struct {
	Name     string
	F        *ast.Field
	Rules    []Validation
	Type     string
	FailFast bool
}

Field is used for storing field information. It holds a reference to the original AST field information to help out if needed.

type Generator

type Generator struct {
	// 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) AddSupportFiles added in v0.1.3

func (g *Generator) AddSupportFiles(inputFiles ...string) error

AddSupportFiles will add the file to the ast.FileSet for parsing, but won't generate anything for the file.

func (*Generator) AddTemplateFiles

func (g *Generator) AddTemplateFiles(filenames ...string) (err error)

AddTemplateFiles will be used during generation when the command line accepts user templates to add to the generation.

func (*Generator) CallTemplate

func (g *Generator) CallTemplate(rule Validation, data interface{}) (ret string, err error)

CallTemplate is a helper method for the template to call a parsed template but with a dynamic name.

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) WithFailFast

func (g *Generator) WithFailFast() *Generator

WithFailFast is used to change all error checks to return immediately on failure.

func (*Generator) WithPointerMethod

func (g *Generator) WithPointerMethod() *Generator

WithPointerMethod is used to change the method generated for a struct to use a pointer receiver rather than a value receiver.

func (*Generator) WithoutPrealloc added in v0.1.2

func (g *Generator) WithoutPrealloc() *Generator

WithoutPrealloc is used to remove preallocation of error array.

type Validation

type Validation struct {
	Name       string
	Param      string
	FieldName  string
	F          *ast.Field
	FieldType  string
	StructName string
	FailFast   bool
	Prealloc   bool
}

Validation is a holder for a validation rule within the generation templates It actually has the same information as the Field struct, simply for ease of access from within the templates.

Jump to

Keyboard shortcuts

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