model

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 3 Imported by: 0

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

func (as Arguments) ContextVarName() string

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

func (as Arguments) ForMethodInvocationWithoutContext() string

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

func (as Arguments) ForMethodSignature() string

ForMethodSignature builds a string that can be used to instantiate the method arguments part of a method declaration template.

func (Arguments) VarNames added in v0.1.2

func (as Arguments) VarNames() string

VarNames builds a string that holds a comma-separated list of all method argument names.

type Import

type Import struct {
	Alias string

	Package string
	// contains filtered or unexported fields
}

Import is an import declaration with an optional Alias and the package path.

type Imports

type Imports struct {
	// contains filtered or unexported fields
}

Imports is a set of Import.

func NewImports

func NewImports() *Imports

func (*Imports) Add

func (il *Imports) Add(newImport Import) string

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

func (il *Imports) ImportStatements() []Import

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

type Method struct {
	Name      string
	Arguments Arguments
	Returns   Returns
}

Method represents a single method of an interface.

func (*Method) AddArgument

func (m *Method) AddArgument(p Param)

AddArgument adds a method argument for this method.

func (*Method) AddReturn

func (m *Method) AddReturn(p Param)

AddReturn adds a method return parameter 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

type Package struct {
	Name string
	Path string
}

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 Params

type Params []Param

Params is a list of params

type Returns

type Returns Params

Returns is the list of method's return parameters.

func (Returns) ErrorVarName

func (rs Returns) ErrorVarName() string

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

func (rs Returns) ForMethodSignature() string

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

func (rs Returns) LastVarTypeIsError() bool

LastVarTypeIsError reports if the last return parameter is of type "error".

func (Returns) ReturnVarNames

func (rs Returns) ReturnVarNames() string

ReturnVarNames builds a comma-separated list of all return parameters variable names.

Jump to

Keyboard shortcuts

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