advice

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBlankImport

func AddBlankImport(path string) addBlankImport

func AddStructField

func AddStructField(fieldName string, fieldType join.TypeName) *addStructField

AddStructField adds a new synthetic field at the tail end of a struct declaration.

func AppendArgs

func AppendArgs(typeName join.TypeName, templates ...*code.Template) *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 AssignValue(template *code.Template) *assignValue

func InjectDeclarations

func InjectDeclarations(template *code.Template, links []string) 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

func PrependStmts(template *code.Template) *prependStatements

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

func ReplaceFunction(path string, name string) *redirectCall

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

func WrapExpression(template *code.Template) *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.

func FromYAML

func FromYAML(node *yaml.Node) (Advice, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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