Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Arguments ¶
type Arguments Params
Arguments is the list of method arguments.
func (Arguments) ContextVarName ¶
ContextVarName returns the name of the variable, that is of type context.Context, but only if it was the first variable to be passed to the method. It returns empty string in any other case.
func (Arguments) ForMethodInvocationWithoutContext ¶
ForMethodInvocationWithoutContext builds a string that holds a comma-separated list of all method argument names without the first context parameter. If the first parameter was not a context it is included in that list too.
This method can be used when passing the arguments down to another method.
func (Arguments) ForMethodSignature ¶
ForMethodSignature builds a string that can be used to instantiate the method arguments part of a method declaration template.
type Imports ¶
type Imports struct {
// contains filtered or unexported fields
}
Imports is a set of Import.
func NewImports ¶
func NewImports() *Imports
func (*Imports) Add ¶
Add adds an Import to the Imports list. It will automatically discover name collisions and assign a custom alias to the new import if such collisions are found. The returned value is the final alias of this package.
Importing the same package multiple times will result in a single Import instance in the list.
func (*Imports) ImportStatements ¶
ImportStatements builds a list of imports that can be used when instantiating the import section of a go source templates. If an import was renamed due to collision the Import alias will be set. If it has the original name resolved form the package path the Alias will be empty.
type Method ¶
Method represents a single method of an interface.
func (*Method) AddArgument ¶
AddArgument adds a method argument for this method.
type Middleware ¶
type Middleware struct { // Imports contain all imports needed by the middleware package. // Within one middleware all imports are uniquely identified by their aliases. Imports *Imports // InterfaceName is the name of the interface we are generating a middleware for. InterfaceName string // OriginalPackage describes the package of the interface we are generating middleware for. OriginalPackage Package // GenPackage holds the name of the package to be set for all middleware files. GenPackage string // Methods holds the discovered methodset of the interface we are generating a middleware for. Methods []Method // contains filtered or unexported fields }
Middleware is the top-level model that wraps all the parsed elements of an Interface. It and its child models all contain methods, that can be used to instantiate a go source template.
func NewMiddleware ¶
func NewMiddleware(forInterfaceName string) *Middleware
NewMiddleware creates a new Middleware instance with the mandatory-needed imports already added.
func (*Middleware) AddMethod ¶
func (mw *Middleware) AddMethod(m Method)
AddMethod adds a new interface method.
func (*Middleware) GetMiddlewareTypesPackageAlias ¶
func (mw *Middleware) GetMiddlewareTypesPackageAlias() string
GetMiddlewareTypesPackageAlias returns the alias of the types package in this library.
func (*Middleware) MiddlewareName ¶
func (mw *Middleware) MiddlewareName() string
MiddlewareName builds the name of the generated middleware based on the original interface name.
func (*Middleware) UniqueImportPaths ¶
func (mw *Middleware) UniqueImportPaths() []Import
UniqueImportPaths returns the generated import statements with custom aliases where needed.
type Package ¶
Package holds a package name and its full import path.
Note that Name here is NOT the alias, but the name it's imported by default. (e.g. module may have package path github.com/yetanotherlogger/log/v2 but the imported package is named "log").
type Param ¶
type Param struct { Name string Type string IsVariadic bool // contains filtered or unexported fields }
Param holds the parameter name and its type ([package name if any].[type]).
type Returns ¶
type Returns Params
Returns is the list of method's return parameters.
func (Returns) ErrorVarName ¶
ErrorVarName returns the name of the (last) error parameter of a method or an empty string if it's not of type "error".
func (Returns) ForMethodSignature ¶
ForMethodSignature builds a string that can be used to instantiate the method return parameters part of a method declaration template.
The result removes the names of named return parameters but keeps them in comments next to the type.
func (Returns) LastVarTypeIsError ¶
LastVarTypeIsError reports if the last return parameter is of type "error".
func (Returns) ReturnVarNames ¶
ReturnVarNames builds a comma-separated list of all return parameters variable names.