Documentation ¶
Index ¶
- func First(i interface{}) (interface{}, error)
- func Last(i interface{}) (interface{}, error)
- func MixedCaps(s string) string
- func NormalizeImportPath(path string) string
- func PackageAbsPath(p interface{}) (string, error)
- func PackageOf(filePath string) (string, error)
- type Generator
- func (g *Generator) AddTemplateFunc(name string, f interface{})
- func (g *Generator) AddTypePrefix(typeName, prefix string)
- func (g *Generator) ConvertType(from, to string)
- func (g *Generator) Copy(n interface{}) error
- func (g *Generator) CopyType(typeSpec *ast.TypeSpec) error
- func (g *Generator) CopyVal(vSpec *ast.ValueSpec) error
- func (g *Generator) ExpressionType(e ast.Expr) (types.Type, error)
- func (g *Generator) FuncParams(f interface{}) (ParamSet, error)
- func (g *Generator) FuncResults(f interface{}) (ParamSet, error)
- func (g *Generator) FuncSignature(f interface{}) (string, error)
- func (g *Generator) Import(pkg interface{}) (path, selector string)
- func (g *Generator) ImportWithAlias(pkg interface{}, alias string) (path string, err error)
- func (g *Generator) New(varName string, varType interface{}) (string, error)
- func (g *Generator) PackagePathAndName(pkg interface{}) (path string, name string)
- func (g *Generator) PackageSelector(pkg interface{}) string
- func (g *Generator) ProcessTemplate(tmplName, tmpl string, data interface{}) error
- func (g *Generator) SetDefaultParamsPrefix(prefix string)
- func (g *Generator) SetDefaultResultsPrefix(prefix string)
- func (g *Generator) SetHeader(h string)
- func (g *Generator) SetPackageName(name string)
- func (g *Generator) SetVar(varName, varValue string)
- func (g *Generator) TypeOf(i interface{}) string
- func (g *Generator) Write(b []byte) (int, error)
- func (g *Generator) WriteTo(w io.Writer) (int64, error)
- func (g *Generator) WriteToFilename(filename string) error
- type Param
- type ParamSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func First ¶
func First(i interface{}) (interface{}, error)
First returns first element of given slice or interface
func Last ¶
func Last(i interface{}) (interface{}, error)
Last returns last element of given slice or interface
func NormalizeImportPath ¶
NormalizeImportPath takes path and return import path relative to deepest nested vendor dir
func PackageAbsPath ¶
PackageAbsPath parses GOPATH environment variable and returns a first absolute path matched the package p import path
Types ¶
type Generator ¶
Generator stores information about imports, loaded packages, registered template functions and global template variables
func (*Generator) AddTemplateFunc ¶
AddTemplateFunc registers a helper function that can be called from any of templates that processed via generator
func (*Generator) AddTypePrefix ¶
func (*Generator) ConvertType ¶
ConvertType sets type conversion rule that will be applied by generator to functions' arguments types structs' fields types and so on.
func (*Generator) Copy ¶
Copy copies entity source to the generated body applying type conversion rules and correct packages aliases
func (*Generator) ExpressionType ¶
ExpressionType searches amoung all loaded packages and returns a type of given ast.Expression
func (*Generator) FuncParams ¶
FuncParams returns a slice of function parameters
func (*Generator) FuncResults ¶
FuncResults returns a slice of function results
func (*Generator) FuncSignature ¶
FuncSignature returns a signature of the function represented by f f can be one of: ast.Expr, ast.SelectorExpr, types.Type, types.Signature
func (*Generator) ImportWithAlias ¶
ImportWithAlias places given package to the list of imported packages and assigns alias to it. It can be useful when you want to use certain alias for the package and give generated aliases for other packages that might have the same name as the given one.
func (*Generator) New ¶
New returns initialization string of the variable according to it's type, i.e. new(..) for pointer types, make(...) for maps/chans and slices, var for arrays and named types, etc
func (*Generator) PackagePathAndName ¶
PackagePathAndName takes package information that can be one of: string, *types.Package, *ast.ImportSpec and returns it's import path and name
func (*Generator) PackageSelector ¶
PackageSelector returns package selector with respect to packages imported with aliases and automatically generated aliases
func (*Generator) ProcessTemplate ¶
ProcessTemplate adds declarations of the global variables registered via SetVar. parses template, registers helper functions to be accessible from template and executes template
func (*Generator) SetDefaultParamsPrefix ¶
func (*Generator) SetDefaultResultsPrefix ¶
func (*Generator) SetPackageName ¶
SetPackageName sets package name of the generated file
func (*Generator) SetVar ¶
SetVar sets global variable that will be accessible from all templates processed with generator
func (*Generator) TypeOf ¶
TypeOf returns a type name for the given argument with package selector. Package selector is generated with respect to packages imported with aliases and automatically generated aliases. Input argument type can be one of: ast.Expr, *Param, types.TypeAndValue, types.Type
func (*Generator) Write ¶
Write implements io.Writer. Performs writing of the byte slice to the generated source body
func (*Generator) WriteToFilename ¶
WriteToFilename write generated source to the file and performs formatting of the source with goimports (which is also doing gofmt internally)
type ParamSet ¶
type ParamSet []*Param
ParamSet is a helper structure that represents list of input or result parameters of a function