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 NewGroup() *group
- 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 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 ¶ added in v0.0.2
func LineComment(content string, args ...interface{}) *istring
func NewGroup ¶ added in v0.1.0
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!")}
Types ¶
type Generator ¶ added in v0.3.0
type Generator struct {
// contains filtered or unexported fields
}
func New ¶ added in v0.3.0
func New() *Generator
New will create a new generator which hold the group reference.
func (*Generator) AppendFile ¶ added in v0.3.0
AppendFile will append the group after the give path.
Click to show internal directories.
Click to hide internal directories.