Documentation
¶
Index ¶
- Constants
- func AddComment(commentList *dst.Decorations, comment string)
- func AddComments(commentList *dst.Decorations, comments []string)
- func AddUnwrappedComment(commentList *dst.Decorations, comment string)
- func AddUnwrappedComments(commentList *dst.Decorations, comments []string)
- func AddWrappedComment(commentList *dst.Decorations, comment string)
- func AddWrappedCommentAtWidth(commentList *dst.Decorations, comment string, width int)
- func AddWrappedComments(commentList *dst.Decorations, comments []string)
- func AddrOf(expr dst.Expr) *dst.UnaryExpr
- func AppendItemToSlice(lhs dst.Expr, rhs dst.Expr) dst.Stmt
- func AppendItemsToSlice(lhs dst.Expr, rhs ...dst.Expr) dst.Stmt
- func AppendSliceToSlice(lhs dst.Expr, rhs dst.Expr) dst.Stmt
- func AreEqual(lhs dst.Expr, rhs dst.Expr) *dst.BinaryExpr
- func AreNotEqual(lhs dst.Expr, rhs dst.Expr) *dst.BinaryExpr
- func AsReference(expr dst.Expr) dst.Expr
- func AssignToInterface(lhsVar string, rhs dst.Expr) dst.Decl
- func AssignmentStatement(lhs dst.Expr, tok token.Token, rhs dst.Expr) *dst.AssignStmt
- func BinaryExpr(lhs dst.Expr, op token.Token, rhs dst.Expr) *dst.BinaryExpr
- func CallExpr(expr dst.Expr, funcName string, arguments ...dst.Expr) *dst.CallExpr
- func CallExprAsStmt(expr dst.Expr, funcName string, arguments ...dst.Expr) dst.Stmt
- func CallFunc(funcName string, arguments ...dst.Expr) *dst.CallExpr
- func CallFuncAsStmt(funcName string, arguments ...dst.Expr) dst.Stmt
- func CallQualifiedFunc(qualifier string, funcName string, arguments ...dst.Expr) *dst.CallExpr
- func CallQualifiedFuncAsStmt(qualifier string, funcName string, arguments ...dst.Expr) dst.Stmt
- func CheckErrorAndReturn(otherReturns ...dst.Expr) dst.Stmt
- func CheckErrorAndSingleStatement(stmt dst.Stmt) dst.Stmt
- func CheckErrorAndWrap(errorsPackage string, message string, args ...dst.Expr) dst.Stmt
- func CommentLength(comments dst.Decorations) int
- func Continue() dst.Stmt
- func Declarations(declarations ...any) []dst.Decl
- func Dereference(expr dst.Expr) dst.Expr
- func Expressions(expressions ...interface{}) []dst.Expr
- func FormatError(fmtPackage string, formatString string, args ...dst.Expr) dst.Expr
- func IfEqual(left dst.Expr, right dst.Expr, statements ...dst.Stmt) *dst.IfStmt
- func IfExprOk(varName string, okName string, expr dst.Expr, statements ...dst.Stmt) *dst.IfStmt
- func IfNil(toCheck dst.Expr, statements ...dst.Stmt) *dst.IfStmt
- func IfNotNil(toCheck dst.Expr, statements ...dst.Stmt) *dst.IfStmt
- func IfNotOk(statements ...dst.Stmt) *dst.IfStmt
- func IfOk(statements ...dst.Stmt) *dst.IfStmt
- func IfType(expr dst.Expr, typeExpr dst.Expr, local string, statements ...dst.Stmt) *dst.IfStmt
- func InsertMap(mapExpr dst.Expr, key dst.Expr, rhs dst.Expr) *dst.AssignStmt
- func IntLiteral(value int) *dst.BasicLit
- func IterateOverMapWithKey(key string, mapExpr dst.Expr, statements ...dst.Stmt) *dst.RangeStmt
- func IterateOverMapWithValue(key string, item string, mapExpr dst.Expr, statements ...dst.Stmt) *dst.RangeStmt
- func IterateOverSlice(item string, list dst.Expr, statements ...dst.Stmt) *dst.RangeStmt
- func IterateOverSliceWithIndex(index string, item string, list dst.Expr, statements ...dst.Stmt) *dst.RangeStmt
- func JoinAnd(exprs ...dst.Expr) dst.Expr
- func JoinBinaryOp(op token.Token, spaceType dst.SpaceType, exprs ...dst.Expr) dst.Expr
- func JoinOr(exprs ...dst.Expr) dst.Expr
- func LocalVariableDeclaration(ident string, typ dst.Expr, comment string) *dst.DeclStmt
- func MakeEmptySlice(listType dst.Expr, capacity dst.Expr) *dst.CallExpr
- func MakeMap(key dst.Expr, value dst.Expr) *dst.CallExpr
- func MakeMapWithCapacity(key dst.Expr, value dst.Expr, capacity dst.Expr) *dst.CallExpr
- func MakeSlice(listType dst.Expr, capacity dst.Expr) *dst.CallExpr
- func NewVariable(varName string, structName string) dst.Stmt
- func NewVariableAssignment(varName string, value dst.Expr) dst.Decl
- func NewVariableAssignmentWithType(varName string, varType dst.Expr, value dst.Expr) dst.Decl
- func NewVariableQualified(varName string, qualifier string, structName string) dst.Stmt
- func NewVariableWithType(varName string, varType dst.Expr) dst.Stmt
- func Nil() *dst.Ident
- func NotEmpty(x dst.Expr) *dst.BinaryExpr
- func NotExpr(expr dst.Expr) *dst.UnaryExpr
- func NotNil(x dst.Expr) *dst.BinaryExpr
- func PointerTo(expr dst.Expr) dst.Expr
- func QualifiedAssignment(lhs dst.Expr, lhsSel string, tok token.Token, rhs dst.Expr) *dst.AssignStmt
- func QualifiedTypeName(pkg string, name string) *dst.SelectorExpr
- func Reduce(operator func(l, r dst.Expr) dst.Expr, spaceType dst.SpaceType, ...) dst.Expr
- func ReturnIfExpr(cond dst.Expr, returns ...dst.Expr) *dst.IfStmt
- func ReturnIfNil(toCheck dst.Expr, returns ...dst.Expr) dst.Stmt
- func ReturnIfNotNil(toCheck dst.Expr, returns ...dst.Expr) dst.Stmt
- func ReturnIfNotOk(returns ...dst.Expr) *dst.IfStmt
- func ReturnIfOk(returns ...dst.Expr) *dst.IfStmt
- func ReturnNoError() dst.Stmt
- func Returns(returns ...dst.Expr) dst.Stmt
- func Selector(expr dst.Expr, names ...string) *dst.SelectorExpr
- func ShortDeclaration(id string, rhs dst.Expr) *dst.AssignStmt
- func SimpleAssignment(lhs dst.Expr, rhs dst.Expr) *dst.AssignStmt
- func SimpleAssignmentWithErr(lhs dst.Expr, tok token.Token, rhs dst.Expr) *dst.AssignStmt
- func SimpleIf(condition dst.Expr, statements ...dst.Stmt) *dst.IfStmt
- func SimpleIfElse(condition dst.Expr, trueBranch []dst.Stmt, falseBranch []dst.Stmt) *dst.IfStmt
- func SliceLiteral(arrayType dst.Expr, items ...dst.Expr) dst.Expr
- func StatementBlock(statements ...dst.Stmt) *dst.BlockStmt
- func Statements(statements ...any) []dst.Stmt
- func StringLiteral(content string) *dst.BasicLit
- func StringLiteralf(format string, a ...interface{}) *dst.BasicLit
- func TextLiteral(content string) *dst.BasicLit
- func TextLiteralf(format string, a ...interface{}) *dst.BasicLit
- func TypeAssert(lhs dst.Expr, rhs dst.Expr, typ dst.Expr) *dst.AssignStmt
- func VariableDeclaration(ident string, typ dst.Expr, comment string) *dst.GenDecl
- func WordWrap(text string, width int) []string
- func WrapError(errorsPackage string, err string, message string, args ...dst.Expr) dst.Expr
- func WrappedError(errorsPackage string, str string) dst.Expr
- func WrappedErrorf(errorsPackage string, template string, args ...interface{}) dst.Expr
- type CompositeLiteralBuilder
- type FuncDetails
- func (fn *FuncDetails) AddComments(comment ...string)
- func (fn *FuncDetails) AddParameter(id string, parameterType dst.Expr)
- func (fn *FuncDetails) AddReturn(expr dst.Expr)
- func (fn *FuncDetails) AddReturns(types ...string)
- func (fn *FuncDetails) AddStatements(statements ...dst.Stmt)
- func (fn *FuncDetails) DefineFunc() *dst.FuncDecl
- func (fn *FuncDetails) DefineFuncHeader() *dst.FuncDecl
- type MapLiteral
- type SliceLiteralBuilder
Constants ¶
const DefaultCommentWrapWidth = 120
Variables ¶
This section is empty.
Functions ¶
func AddComment ¶
func AddComment(commentList *dst.Decorations, comment string)
AddComment adds a single comment line to the specified list
func AddComments ¶
func AddComments(commentList *dst.Decorations, comments []string)
AddComments adds preformatted comments to the specified list
func AddUnwrappedComment ¶
func AddUnwrappedComment(commentList *dst.Decorations, comment string)
AddUnwrappedComment adds a single comment to the specified list. The text is not wrapped. Respects any existing line breaks specified by \n or <br>.
func AddUnwrappedComments ¶
func AddUnwrappedComments(commentList *dst.Decorations, comments []string)
AddUnwrappedComments adds comments to the specified list. The text is not wrapped. Respects any existing line breaks specified by \n or <br>
func AddWrappedComment ¶
func AddWrappedComment(commentList *dst.Decorations, comment string)
AddWrappedComment adds a single comment to the specified list, wrapping text as it goes. Respects any existing line breaks specified by \n or <br>
func AddWrappedCommentAtWidth ¶
func AddWrappedCommentAtWidth(commentList *dst.Decorations, comment string, width int)
AddWrappedCommentAtWidth adds a single comment to the specified list, wrapping text to the specified width as it goes. Respects any existing line breaks specified by \n or <br>
func AddWrappedComments ¶
func AddWrappedComments(commentList *dst.Decorations, comments []string)
AddWrappedComments adds comments to the specified list, wrapping text to the specified width as it goes. Respects any existing line breaks specified by \n or <br>
func AppendItemToSlice ¶
AppendItemToSlice returns a statement to append a single item to a slice
<lhs> = append(<lhs>, <rhs>)
func AppendItemsToSlice ¶
AppendItemsToSlice returns a statement to append many individual items to a slice
<lhs> = append(<lhs>, <rhs>, <rhs>, <rhs>, ...)
func AppendSliceToSlice ¶
AppendSliceToSlice returns a statement to append a slice to another slice
<lhs> = append(<lhs>, <rhs>...)
func AsReference ¶
AsReference returns a statement that is a reference to the supplied expression
&<expr>
If the expression given is a StarExpr dereference, we unwrap it instead of taking its address
func AssignToInterface ¶
AssignToInterface performs an assignment of a well-typed variable to an interface{}. This is usually used to perform a type assertion on a concrete type in a subsequent statement (which Go doesn't allow, it only allows type assertions on interface types).
var <lhsVar> interface{} = <rhs>
func AssignmentStatement ¶
AssignmentStatement allows for either variable declaration or assignment by passing the required token Only token.DEFINE and token.ASSIGN are supported, other values will panic. Use SimpleAssignment or ShortDeclaration if possible; use this method only if you must.
func BinaryExpr ¶
func CallExpr ¶
CallExpr creates an expression to call the named function with the specified arguments
<expr>.<funcName>(arguments...)
func CallExprAsStmt ¶
CallExprAsStmt creates a statement to invoke the named function with the specified arguments
<expr>.<funcName>(arguments...)
If you want to use the result of the function call as a value, use CallExpr() instead
func CallFunc ¶
CallFunc creates an expression to call a function with specified arguments
<funcName>(<arguments>...)
func CallFuncAsStmt ¶
CallFuncAsStmt creates a statement to invoke a function with specified arguments
<funcName>(arguments...)
If you want to use the result of the function call as a value, use CallFunc() instead
func CallQualifiedFunc ¶
CallQualifiedFunc creates an expression to call a qualified function with the specified arguments
<qualifier>.<funcName>(arguments...)
func CallQualifiedFuncAsStmt ¶
CallQualifiedFuncAsStmt creates a statement to invoke a qualified function with specified arguments
<qualifier>.<funcName>(arguments...)
If you want to use the result of the function call as a value, use CallQualifiedFunc() instead
func CheckErrorAndReturn ¶
CheckErrorAndReturn checks if the err is non-nil, and if it is returns.
if err != nil { return <otherReturns...>, err }
func CheckErrorAndSingleStatement ¶
CheckErrorAndSingleStatement checks if the err is non-nil, and if it is executes the provided statement.
if err != nil { <stmt> }
func CheckErrorAndWrap ¶
CheckErrorAndWrap checks if the err is non-nil, and if it is returns it, wrapped with additional information If no arguments are provided, will generate
if err != nil { return errors.Wrap(err, <message>) }
otherwise will generate
if err != nil { return errors.Wrapf(err, <message>, <args>) }
func CommentLength ¶
func CommentLength(comments dst.Decorations) int
CommentLength returns the text length of the comments, including EoLN characters
func Declarations ¶
Declarations constructs a slice of dst.Decl by combining the given declarations. Pass any combination of dst.Decl and []dst.Decl as arguments; anything else will result in a runtime panic.
func Dereference ¶
Dereference returns a statement that dereferences the pointer returned by the provided expression
*<expr>
func Expressions ¶
Expression creates a slice of dst.Expr by combining the given expressions. Pass any combination of dst.Expr and []dst.Expr as arguments; anything else will result in a runtime panic.
func FormatError ¶
FormatError produces a call to fmt.Errorf with the given format string and args
fmt.Errorf(<formatString>, <args>)
func IfEqual ¶
IfEqual executes a series of statements if the supplied expressions are
if <left> == <right> { <statements> }
func IfExprOk ¶
IfExprOk evaluates an expression returning two values and executes the provided statements if the second value is true varName is the name of the variable to assign the first value to; okName is the name of the variable to assign the second value to; expr is the expression to evaluate; statements form the body of the if statement
func IfNil ¶
IfNil executes a series of statements if the supplied expression is nil
if <source> != nil { <statements> }
func IfNotNil ¶
IfNotNil executes a series of statements if the supplied expression is not nil
if <source> != nil { <statements> }
func IfNotOk ¶
IfNotOk checks a boolean ok variable and if it is not ok runs the given statements
if !ok { <statements> }
func IfOk ¶
IfOk checks a boolean ok variable and if it is ok runs the given statements
if ok { <statements> }
func IfType ¶
IfType does a type assertion and executes the provided statements if it is true expr is the expression to cast; typeExpr is the type we want to cast to; local is the name of the local variable to initialize statements form the body of the if statement
if <local>, ok := <expr>.(<typeExpr>); ok { <statements> }
func InsertMap ¶
InsertMap returns an assignment statement for inserting an item into a map
<mapExpr>[<key>] = <rhs>
func IntLiteral ¶
IntLiteral create the AST node for a literal integer value
func IterateOverMapWithKey ¶
IterateOverMapWithKey creates a statement to iterate over the content of a map using the specified identifiers for each key and value found.
for <key> := range <mapExpr> { <statements> }
func IterateOverMapWithValue ¶
func IterateOverMapWithValue(key string, item string, mapExpr dst.Expr, statements ...dst.Stmt) *dst.RangeStmt
IterateOverMapWithValue creates a statement to iterate over the content of a map using the specified identifiers for each key and value found.
for <key>, <item> := range <mapExpr> { <statements> }
func IterateOverSlice ¶
IterateOverSlice creates a statement to iterate over the content of a list using the specified identifier for each element in the list
for _, <item> := range <list> { <statements> }
func IterateOverSliceWithIndex ¶
func IterateOverSliceWithIndex(index string, item string, list dst.Expr, statements ...dst.Stmt) *dst.RangeStmt
IterateOverSliceWithIndex creates a statement to iterate over the content of a list using the specified identifiers for each index and element in the list
for <index>, <item> := range <list> { <statements> }
func JoinBinaryOp ¶
JoinBinaryOp combines a sequence of expressions using a given operator op defines the operator to use to combine two adjacent expressions. spaceType specifies what kind of whitespace is needed after each one. exprs is the sequence of expressions to combine.
func JoinOr ¶
JoinOr combines a sequence of expressions with the OR (||) operator If there are more than two expressions to combine, they're broken out on separate lines
func LocalVariableDeclaration ¶
LocalVariableDeclaration performs a local variable declaration for use within a method
var <ident> <typ>
func MakeEmptySlice ¶
MakeEmptySlice returns the call expression for making a slice with a specified length that can be appended to using append(...)
make([]<value>, 0, <len>)
func MakeMapWithCapacity ¶
MakeMapWithCapacity returns the call expression for making a map with a predefined capacity
make(map[<key>]<value>, <capacity>)
func MakeSlice ¶
MakeSlice returns the call expression for making a slice with a specified length
make([]<value>, <capacity>)
func NewVariable ¶
NewVariable creates a new declaration statement where a variable is declared with its default value.
For example:
var <varName> <structName>
Note that it does *not* do:
<varName> := <structName>{}
…as that does not work for enum types.
func NewVariableAssignment ¶
NewVariableAssignmentWithType creates a new statement where a variable is declared with an implicit type. var <varName> <varType> = <varValue>
func NewVariableAssignmentWithType ¶
NewVariableAssignmentWithType creates a new statement where a variable is declared with an explicit type. var <varName> <varType> = <varValue>
func NewVariableQualified ¶
NewVariableQualified creates a new declaration statement where a variable is declared with its default value.
For example:
var <varName> <packageRef>.<structName>
Note that it does *not* do:
<varName> := <packageRef>.<structName>{}
…as that does not work for enum types.
func NotEmpty ¶
func NotEmpty(x dst.Expr) *dst.BinaryExpr
NotEmpty generates an `len(x) > 0` condition
func PointerTo ¶
PointerTo returns a statement that dereferences the pointer returned by the provided expression
*<expr>
Yes, this is identical to Dereference, but having both makes the code more readable
func QualifiedAssignment ¶
func QualifiedAssignment(lhs dst.Expr, lhsSel string, tok token.Token, rhs dst.Expr) *dst.AssignStmt
QualifiedAssignment performs a simple assignment like:
<lhs>.<lhsSel> := <rhs> // tok = token.DEFINE
or <lhs>.<lhsSel> = <rhs> // tok = token.ASSIGN
func QualifiedTypeName ¶
func QualifiedTypeName(pkg string, name string) *dst.SelectorExpr
QualifiedTypeName generates a reference to a type within an imported package
<pkg>.<name>
func Reduce ¶
func Reduce(operator func(l, r dst.Expr) dst.Expr, spaceType dst.SpaceType, exprs ...dst.Expr) dst.Expr
Reduce combines a sequence of expressions using the provided function. operator defines how to combine two adjacent expressions. spaceType specifies what kind of whitespace is needed after each one. exprs is the sequence of expressions to combine.
func ReturnIfExpr ¶
ReturnIfExpr returns if the expression evaluates as true
if <cond> { return <returns...> }
func ReturnIfNil ¶
ReturnIfNil checks if a variable is nil and if it is returns
if <toCheck> == nil { return <returns...> }
func ReturnIfNotNil ¶
ReturnIfNotNil checks if a variable is not nil and if it is returns
if <toCheck> != nil { return <returns...> }
func ReturnIfNotOk ¶
ReturnIfNotOk checks a boolean ok variable and if it is not ok returns the specified values
if !ok { return <returns> }
func ReturnIfOk ¶
ReturnIfOk checks a boolean ok variable and if it is ok returns the specified values
if ok { return <returns> }
func ReturnNoError ¶
ReturnNoError creates a return nil statement for when no error occurs
// No error return nil
func Returns ¶
Returns creates a return statement with one or more expressions, of the form
return <expr>
or return <expr>, <expr>, ...
func Selector ¶
func Selector(expr dst.Expr, names ...string) *dst.SelectorExpr
Selector generates a field reference into an existing expression
<expr>.<name0>.(<name1>.<name2>…)
func ShortDeclaration ¶
func ShortDeclaration(id string, rhs dst.Expr) *dst.AssignStmt
ShortDeclaration performs a simple assignment like:
<id> := <rhs>
Method naming inspired by https://tour.golang.org/basics/10
func SimpleAssignment ¶
SimpleAssignment performs a simple assignment like:
<lhs> = <rhs>
See also ShortDeclaration
func SimpleAssignmentWithErr ¶
SimpleAssignmentWithErr performs a simple assignment like:
<lhs>, err := <rhs> // tok = token.DEFINE or <lhs>, err = <rhs> // tok = token.ASSIGN
func SimpleIf ¶
SimpleIf creates a simple if statement with multiple statements
if <condition> { <trueBranch> }
func SimpleIfElse ¶
SimpleIfElse creates a simple if else statement. Each branch may contain multiple statements.
if <condition> { <trueBranch> } else { <falseBranch> }
func StatementBlock ¶
StatementBlock generates a block containing the supplied statements If we're given a single statement that's already a block, we won't double wrap it
func Statements ¶
Statements creates a slice of dst.Stmt by combining the given statements. Pass any combination of dst.Stmt and []dst.Stmt as arguments; anything else will result in a runtime panic.
func StringLiteral ¶
StringLiteral creates the AST node for a literal string value Leading and trailing quotes are added as required and any existing quotes are escaped
func StringLiteralf ¶
StringLiteralf creates the AST node for a literal string value based on a format string Leading and trailing quotes are added as required and any existing quotes are escaped
func TextLiteral ¶
TextLiteral creates the AST node for a literal text value No additional text is included
func TextLiteralf ¶
TextLiteralf creates the AST node for literal text based on a format string
func TypeAssert ¶
TypeAssert returns an assignment statement with a type assertion
<lhs>, ok := <rhs>.(<type>)
func VariableDeclaration ¶
VariableDeclaration performs a global variable declaration
// <comment> var <ident> <typ>
For a LocalVariable within a method, use LocalVariableDeclaration() to create an ast.Stmt instead
func WordWrap ¶
WordWrap applies word wrapping to the specified string, returning a slice containing the lines.
func WrapError ¶
WrapError wraps the specified err. If no arguments are provided, will generate
errors.Wrap(err, <message>)
otherwise will generate
errors.Wrapf(err, <message>, <args>)
func WrappedError ¶
WrappedError returns the err local, wrapped with additional information
errors.Wrap(err, <message>)
(actual package name will be used, which will usually be 'errors')
Types ¶
type CompositeLiteralBuilder ¶
type CompositeLiteralBuilder struct {
// contains filtered or unexported fields
}
CompositeLiteralBuilder captures the information required to generate code for an inline struct initialization
func NewCompositeLiteralBuilder ¶
func NewCompositeLiteralBuilder(structType dst.Expr) *CompositeLiteralBuilder
NewCompositeLiteralBuilder creates a new instance for initialization of the specified struct structType is an expression to handle both structs from the current package and imported ones requiring qualification
func (*CompositeLiteralBuilder) AddField ¶
func (b *CompositeLiteralBuilder) AddField(name string, value dst.Expr) *CompositeLiteralBuilder
AddField adds initialization of another field Returns the receiver to allow method chaining when desired
func (*CompositeLiteralBuilder) Build ¶
func (b *CompositeLiteralBuilder) Build() *dst.CompositeLit
Build constructs the actual dst.CompositeLit that's required
func (*CompositeLiteralBuilder) WithoutNewLines ¶
func (b *CompositeLiteralBuilder) WithoutNewLines() *CompositeLiteralBuilder
WithoutNewLines returns the CompositeLiteralBuilder without NewLines enabled
type FuncDetails ¶
type FuncDetails struct { ReceiverIdent string ReceiverType dst.Expr Name string Comments []string Params []*dst.Field Returns []*dst.Field Body []dst.Stmt }
func NewTestFuncDetails ¶
func NewTestFuncDetails(testingPackage string, testName string, body ...dst.Stmt) *FuncDetails
NewTestFuncDetails returns a FuncDetails for a test method Tests require a particular signature, so this makes it simpler to create test functions
func (*FuncDetails) AddComments ¶
func (fn *FuncDetails) AddComments(comment ...string)
AddComments adds multiple comments to the function declaration
func (*FuncDetails) AddParameter ¶
func (fn *FuncDetails) AddParameter(id string, parameterType dst.Expr)
AddParameter adds another parameter to the function definition
func (*FuncDetails) AddReturn ¶
func (fn *FuncDetails) AddReturn(expr dst.Expr)
AddReturn adds a single return value to the function definition
func (*FuncDetails) AddReturns ¶
func (fn *FuncDetails) AddReturns(types ...string)
AddReturns adds (possibly many) return values to the function definition
func (*FuncDetails) AddStatements ¶
func (fn *FuncDetails) AddStatements(statements ...dst.Stmt)
AddStatements adds additional statements to the function
func (*FuncDetails) DefineFunc ¶
func (fn *FuncDetails) DefineFunc() *dst.FuncDecl
DefineFunc defines a function (header, body, etc), like:
<comment> func (<receiverIdent> <receiverType>) <name>(<params...>) (<returns...>) { <body...> }
func (*FuncDetails) DefineFuncHeader ¶
func (fn *FuncDetails) DefineFuncHeader() *dst.FuncDecl
DefineFuncHeader defines a function header like:
<comment> func (<receiverIdent> <receiverType>) <name>(<params...>) (<returns...>)
type MapLiteral ¶
type MapLiteral struct {
// contains filtered or unexported fields
}
func NewMapLiteral ¶
func NewMapLiteral(key dst.Expr, value dst.Expr) *MapLiteral
func (*MapLiteral) AsExpr ¶
func (m *MapLiteral) AsExpr() dst.Expr
type SliceLiteralBuilder ¶
type SliceLiteralBuilder struct {
// contains filtered or unexported fields
}
SliceLiteralBuilder captures the information required to generate code for an inline slice initialization
func NewSliceLiteralBuilder ¶
func NewSliceLiteralBuilder(sliceType dst.Expr, linePerElement bool) *SliceLiteralBuilder
NewSliceLiteralBuilder creates a new instance for initialization of the specified slice The linePerElt parameter determines if the slice literal should have a single element per line
func (*SliceLiteralBuilder) AddElement ¶
func (b *SliceLiteralBuilder) AddElement(element dst.Expr) *SliceLiteralBuilder
AddElement adds an element to the slice literal Returns the receiver to allow method chaining when desired
func (*SliceLiteralBuilder) Build ¶
func (b *SliceLiteralBuilder) Build() dst.Expr
Build constructs the actual dst.CompositeLit describing the slice literal