Documentation ¶
Overview ¶
Package advice provides implementations of the injector.Action interface for common AST changes.
Package advice provides implementations of the injector.Action interface for common AST changes.
Index ¶
- func AddBlankImport(path string) addBlankImport
- func AddStructField(fieldName string, fieldType join.TypeName) *addStructField
- func AppendArgs(typeName join.TypeName, templates ...*code.Template) *appendArgs
- func AssignValue(template *code.Template) *assignValue
- func InjectDeclarations(template *code.Template, links []string) injectDeclarations
- func PrependStmts(template *code.Template) *prependStatements
- func ReplaceFunction(path string, name string) *redirectCall
- func WrapExpression(template *code.Template) *wrapExpression
- type Advice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddBlankImport ¶
func AddBlankImport(path string) addBlankImport
func AddStructField ¶
AddStructField adds a new synthetic field at the tail end of a struct declaration.
func AppendArgs ¶
AppendArgs appends arguments of a given type to the end of a function call. All arguments must be of the same type, as they may be appended at the tail end of a variadic call.
func AssignValue ¶
func InjectDeclarations ¶
InjectDeclarations merges all declarations in the provided source file into the current file. The package name of both original & injected files must match.
func PrependStmts ¶
PrependStmts prepends statements to the matched *dst.BlockStmt. This action can only be used if the selector matches on a *dst.BlockStmt. The prepended statements are wrapped in a new block statement to prevent scope leakage.
func ReplaceFunction ¶
ReplaceFunction replaces the called function with the provided drop-in replacement. The signature must be compatible with the original function (it may accept a new variadic argument).
func WrapExpression ¶
Types ¶
type Advice ¶
type Advice interface { // AddedImports returns the list of import paths the receiver may introduce in // modified code. AddedImports() []string // Apply performs the necessary AST changes on the supplied node. It returns a // boolean indicating whether the node was modified or not (some actions may // short-circuit and not do anything; e.g. import injection may be skipped if // the import already exists). Apply(context.AdviceContext) (bool, error) fingerprint.Hashable }
Advice is the interface abstracting actual AST changes performed by injections.