Command gencodec generates marshaling methods for Go struct types.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gencodec/vendor/github.com/garslo/gogen/README.md

955 B

gogen

A simplification of Go's go/ast package that allows for some interesting code generation. Currently very rough.

Examples

Hello World

package main

import (
	"os"
	. "github.com/garslo/gogen"
)

func main() {
	pkg := Package{Name: "main"}
	pkg.Declare(Import{"fmt"})
	pkg.Declare(Function{
		Name: "main",
		Body: []Statement{
			CallFunction{
				Func:   Dotted{Var{"fmt"}, "Println"},
				Params: []Expression{Var{`"Hello World!"`}},
			},
		},
	})
	pkg.WriteTo(os.Stdout)
}

Output:

package main

import "fmt"

func main() {
	fmt.Println("Hello World!")
}

More

See the examples directory for more examples and a build/run script.

$ ./run-example.sh for_loop.go
CODE:
package main

import "os"
import "fmt"

func main() {
	var i int
	for i = 0; i <= 10; i++ {
		fmt.Println(i)
	}
	os.Exit(i)
}
RUN RESULT:
0
1
2
3
4
5
6
7
8
9
10
exit status 11