Documentation ¶
Index ¶
- Variables
- func Call(name string) *icall
- func Const() *iconst
- func For(judge interface{}) *ifor
- func Function(name string) *ifunction
- func If(judge interface{}) *iif
- func Import() *iimport
- func Interface(name string) *iinterface
- func LineComment(content string, args ...interface{}) *istring
- func Lit(value interface{}) *lit
- func Package(name string) *ipackage
- func Return(node ...interface{}) *ireturn
- func String(format string, args ...interface{}) *istring
- func Struct(name string) *istruct
- func Switch(judge interface{}) *iswitch
- func Type(name string, typ interface{}) *itype
- func TypeAlias(name string, typ interface{}) *itype
- func Value(typ string) *ivalue
- func Var() *ivar
- type Generator
- type Group
- func (g *Group) AddLine() *Group
- func (g *Group) AddLineComment(content string, args ...interface{}) *Group
- func (g *Group) AddPackage(name string) *Group
- func (g *Group) AddString(content string, args ...interface{}) *Group
- func (g *Group) AddType(name string, typ interface{}) *Group
- func (g *Group) AddTypeAlias(name string, typ interface{}) *Group
- func (g *Group) AppendFile(path string) errordeprecated
- func (g *Group) NewConst() *iconst
- func (g *Group) NewFor(judge interface{}) *ifor
- func (g *Group) NewFunction(name string) *ifunction
- func (g *Group) NewIf(judge interface{}) *iif
- func (g *Group) NewImport() *iimport
- func (g *Group) NewInterface(name string) *iinterface
- func (g *Group) NewStruct(name string) *istruct
- func (g *Group) NewSwitch(judge interface{}) *iswitch
- func (g *Group) NewVar() *ivar
- func (g *Group) String() string
- func (g *Group) Write(w io.Writer)deprecated
- func (g *Group) WriteFile(path string) errordeprecated
- type Node
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var S = String
S is an alias to String. TODO: can we find a new name for this?
Functions ¶
func Function ¶
func Function(name string) *ifunction
Function represent both method and function in Go.
NOTES ¶
If `WithReceiver`, we will generate a method:
func (t test) Test()
If `WithCall`, we will generate a function call:
func Test(){}()
If `AddBody`, we will generate like a function definition without body:
func Test() { println("Hello, World!") }
func LineComment ¶
func LineComment(content string, args ...interface{}) *istring
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
func (*Generator) AppendFile ¶
AppendFile will append the group after the give path.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func NewGroup ¶
func NewGroup() *Group
Example ¶
f := NewGroup() f.AddPackage("main") f.NewImport().AddPath("fmt") f.NewFunction("main").AddBody( String(`fmt.Println("%s")`, "Hello, World!"), ) fmt.Println(f.String())
Output: package main import "fmt" func main(){ fmt.Println("Hello, World!")}
func (*Group) AddLineComment ¶
func (*Group) AddPackage ¶
func (*Group) AddTypeAlias ¶
func (*Group) AppendFile
deprecated
func (*Group) NewFunction ¶
func (*Group) NewInterface ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.