Documentation ¶
Overview ¶
Package gen provides functions for generating go source code
The gen package provides wrapper functions around the go/ast and go/token packages to reduce boilerplate.
Index ¶
- func CommentGroup(comments ...string) *ast.CommentGroup
- func ConstChar(args ...string) *ast.GenDecl
- func ConstFloat(args ...string) *ast.GenDecl
- func ConstImaginary(args ...string) *ast.GenDecl
- func ConstInt(args ...string) *ast.GenDecl
- func ConstString(args ...string) *ast.GenDecl
- func Declarations(blocks ...string) ([]ast.Decl, error)
- func ExprString(expr ast.Expr) string
- func Field(name, typ, tag ast.Expr, annotation string) *ast.Field
- func FieldList(fields ...string) (*ast.FieldList, error)
- func FormattedSource(file *ast.File, output string) ([]byte, error)
- func PackageDoc(file *ast.File, comments ...string) *ast.File
- func Public(name string) *ast.Ident
- func Sanitize(name string) string
- func SimpleType(name string) ast.Expr
- func Snippets(val interface{}, snippets ...string) ([]ast.Decl, error)
- func String(s string) *ast.BasicLit
- func TagKey(field *ast.Field, key string) string
- func ToString(expr ast.Expr) (string, error)
- func TypeDecl(name *ast.Ident, typ ast.Expr) *ast.GenDecl
- type Function
- func (fn *Function) Args(args ...string) *Function
- func (fn *Function) Body(format string, v ...interface{}) *Function
- func (fn *Function) BodyTmpl(tmpl string, dot interface{}) *Function
- func (fn *Function) Comment(s string) *Function
- func (fn *Function) Decl() (*ast.FuncDecl, error)
- func (fn *Function) MustDecl() *ast.FuncDecl
- func (fn *Function) Name() string
- func (fn *Function) Receiver(receiver string) *Function
- func (fn *Function) Returns(values ...string) *Function
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommentGroup ¶
func CommentGroup(comments ...string) *ast.CommentGroup
CommentGroup creates a comment group from strings.
func ConstChar ¶
ConstChar creates a series of character const declarations from the name/value pairs in args.
func ConstFloat ¶
ConstFloat creates a series of floating-point const declarations from the name/value pairs in args.
func ConstImaginary ¶
ConstImaginary creates a series of imaginary const declarations from the name/value pairs in args.
func ConstInt ¶
ConstInt creates a series of numeric const declarations from the name/value pairs in args.
func ConstString ¶
ConstString creates a series of string const declarations from the name/value pairs in args.
func Declarations ¶
Declarations parses a list of Go source code blocks and converts them into *ast.Decl values. If a parsing error occurs, it is returned immediately and no further parsing takes place.
func ExprString ¶
ExprString converts an ast.Expr to the Go source it represents.
func FormattedSource ¶
FormattedSource converts an abstract syntax tree to formatted Go source code.
func PackageDoc ¶
PackageDoc inserts package-level comments into a file, preceding the "package" statement.
func Sanitize ¶
Sanitize modifies any names that are reserved in Go, so that they may be used as identifiers without causing a syntax error.
func SimpleType ¶
SimpleType creates an identifier suitable for use as a type expression.
func Snippets ¶
Snippets evaluates zero or more input templates with dot set to val and parses them as Go source code.
func String ¶
String generates a literal string. If the string contains a double quote, backticks are used for quoting instead.
Types ¶
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
func (*Function) Body ¶
Body sets the body of a function. The body should not include enclosing braces.
func (*Function) BodyTmpl ¶
BodyTmpl allows use of the text/template package to construct the body of a function.
func (*Function) Decl ¶
Decl generates Go source for a Func. an error is returned if the body, or parameters cannot be parsed.