Documentation ¶
Index ¶
- func Asset(name string) ([]byte, error)
- func AssetDigest(name string) ([sha256.Size]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func AssetString(name string) (string, error)
- func Digests() (map[string][sha256.Size]byte, error)
- func GenerationError(s string) (ret interface{}, err error)
- func MustAsset(name string) []byte
- func MustAssetString(name string) string
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type Field
- type Generator
- func (g *Generator) AddSupportFiles(inputFiles ...string) error
- func (g *Generator) AddTemplateFiles(filenames ...string) (err error)
- func (g *Generator) CallTemplate(rule Validation, data interface{}) (ret string, err error)
- func (g *Generator) Generate(f *ast.File) ([]byte, error)
- func (g *Generator) GenerateFromFile(inputFile string) ([]byte, error)
- func (g *Generator) WithFailFast() *Generator
- func (g *Generator) WithPointerMethod() *Generator
- func (g *Generator) WithoutPrealloc() *Generator
- type Validation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Asset ¶
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
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 ¶
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 ¶
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 AssetString ¶ added in v0.1.3
AssetString returns the asset contents as a string (instead of a []byte).
func GenerationError ¶
GenerationError is a helper method for templates to generate an error if something is unsupported.
func MustAsset ¶
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
MustAssetString is like AssetString but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory.
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively.
Types ¶
type Field ¶
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
AddSupportFiles will add the file to the ast.FileSet for parsing, but won't generate anything for the file.
func (*Generator) AddTemplateFiles ¶
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 ¶
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.
func (*Generator) WithFailFast ¶
WithFailFast is used to change all error checks to return immediately on failure.
func (*Generator) WithPointerMethod ¶
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
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.