Documentation
¶
Index ¶
- type FileGen
- func (g *FileGen) AddOrGetImport(pkgPath string) (importPrefix string)
- func (g *FileGen) CreateIdent(namePrefix string) *ast.Ident
- func (g *FileGen) PatchFuncDecl(name string) *FuncGen
- func (g *FileGen) TypeExpr(typ reflect.Type) (ast.Expr, error)
- func (g *FileGen) ValueExpr(value reflect.Value) (ast.Expr, error)
- type FuncGen
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileGen ¶
FileGen is a utility for generating/patching golang file ASTs.
func NewFileGen ¶
NewFileGen creates a new FileGen instance from a file AST with the provided package path.
func (*FileGen) AddOrGetImport ¶
AddOrGetImport adds a new import for the provided pkgPath (if needed) and returns the unique import prefix for that path.
func (*FileGen) CreateIdent ¶
CreateIdent creates a new ident that doesn't conflict with reserved symbols, top-level declarations and other defined idents. Idents are unique across the whole file as it is assumed that codegen usually happens on one function per file.
func (*FileGen) PatchFuncDecl ¶
PatchFuncDecl returns a FuncGen instance for the function declaration with the given name or returns nil.
func (*FileGen) TypeExpr ¶
TypeExpr generates an ast.Expr to be used in the context of the file for the provided reflect.Type, adding any needed imports.