Documentation
¶
Index ¶
- type Generator
- type Method
- func (m Method) Call() string
- func (m Method) Declaration() string
- func (m Method) HasParams() bool
- func (m Method) HasResults() bool
- func (m Method) ParamPtrsStruct() string
- func (m Method) ParamsMap() string
- func (m Method) ParamsNames() string
- func (m Method) ParamsStruct() string
- func (m Method) Pass(prefix string) string
- func (m Method) ResultsMap() string
- func (m Method) ResultsNames() string
- func (m Method) ResultsStruct() string
- func (m Method) ReturnStruct(structName string) string
- func (m Method) Signature() string
- type Options
- type PackageCache
- type Param
- type ParamsSlice
- type TemplateInputGenerics
- type TemplateInputInterface
- type TemplateInputs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
Options
// contains filtered or unexported fields
}
Generator generates decorators for the interface types
func NewGenerator ¶
NewGenerator returns Generator initialized with options
type Method ¶
type Method struct {
Doc []string
Comment []string
Name string
Params ParamsSlice
Results ParamsSlice
ReturnsError bool
AcceptsContext bool
}
Method represents a method's signature
func NewMethod ¶
func NewMethod(name string, fi *ast.Field, printer typePrinter, genericTypes genericTypes, genericParams genericParams) (*Method, error)
NewMethod returns pointer to Signature struct or error
func (Method) Declaration ¶
Declaration returns a method name followed by it's signature
func (Method) HasResults ¶
HasResults returns true if method has results
func (Method) ParamPtrsStruct ¶
ParamPtrsStruct returns a struct type with pointer fields corresponding to the method params
func (Method) ParamsMap ¶
ParamsMap returns a string representation of the map[string]interface{} filled with method's params
func (Method) ParamsNames ¶
ParamsNames returns a list of method params names
func (Method) ParamsStruct ¶
ParamsStruct returns a struct type with fields corresponding to the method params
func (Method) ResultsMap ¶
ResultsMap returns a string representation of the map[string]interface{} filled with method's results
func (Method) ResultsNames ¶
ResultsNames returns a list of method results names
func (Method) ResultsStruct ¶
ResultsStruct returns a struct type with fields corresponding to the method results
func (Method) ReturnStruct ¶
ReturnStruct returns return statement with the return params taken from the structName
type Options ¶
type Options struct {
InterfaceName string
Imports []string
SourcePackage string
SourcePackageInstance *packages.Package
SourcePackageAST *scanner.Package
SourcePackageAlias string
OutputFile string
DestinationPackageInstance *packages.Package
HeaderTemplate string
BodyTemplate string
Vars map[string]interface{}
HeaderVars map[string]interface{}
Funcs template.FuncMap
LocalPrefix string
SkipImportsProcessing bool
HeaderTemplateParsed *template.Template
BodyTemplateParsed *template.Template
FileSet *token.FileSet
PackageCache *PackageCache
}
Options of the NewGenerator constructor
type PackageCache ¶
type PackageCache struct {
// contains filtered or unexported fields
}
PackageCache caches loaded packages and parsed ASTs to avoid redundant work when multiple interfaces reference the same external packages. All methods are safe for concurrent use by multiple goroutines.
func NewPackageCache ¶
func NewPackageCache() *PackageCache
NewPackageCache returns an empty PackageCache.
type Param ¶
Param represents fuction argument or result
type ParamsSlice ¶
type ParamsSlice []Param
ParamsSlice slice of parameters
func (ParamsSlice) Pass ¶
func (ps ParamsSlice) Pass() string
Pass returns comma separated params names to be passed to a function call with respect to variadic functions
type TemplateInputGenerics ¶
TemplateInputGenerics subset of generics interface information used for template generation
type TemplateInputInterface ¶
type TemplateInputInterface struct {
Name string
Type string
Generics TemplateInputGenerics
Methods map[string]Method
}
TemplateInputInterface subset of interface information used for template generation
type TemplateInputs ¶
type TemplateInputs struct {
Interface TemplateInputInterface
Vars map[string]interface{}
Imports []string
}
TemplateInputs information passed to template for generation
func (TemplateInputs) Import ¶
func (t TemplateInputs) Import(imports ...string) string
Import generates an import statement using a list of imports from the source file along with the ones from the template itself