Beispiel #1
0
func (me Go) Emit(state config.State) error {
	pkg := g.Package{
		Name: "config",
	}
	for _, t := range state.Types {
		fields := make([]g.Field, len(t.Params))
		for i, param := range t.Params {
			fields[i] = g.Field{
				Name:     makeGoName(param.GoName, param.Name),
				TypeName: typeName(state.Types, param.Type),
				Tag:      fmt.Sprintf("`yaml:\"%s\"`", param.Name),
			}
		}
		pkg.Declare(g.Struct{
			Name:   makeGoName(t.GoName, t.Name),
			Fields: fields,
		})
	}
	return pkg.WriteTo(os.Stdout)
}
Beispiel #2
0
package gogen_test

import (
	g "github.com/garslo/gogen"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Package", func() {
	var (
		pkg g.Package
	)

	BeforeEach(func() {
		pkg = g.Package{}
	})

	It("should add functions", func() {
		pkg.Declare(g.Function{})
		Expect(pkg.Declarations).To(HaveLen(1))
	})

	It("should add imports", func() {
		pkg.Declare(g.Import{"os"})
		Expect(pkg.Declarations).To(HaveLen(1))
	})
})