templateUtil.go 569 Bytes
Newer Older
Eric Myhre's avatar
Eric Myhre committed
1 2 3 4 5 6
package gengo

import (
	"io"
	"text/template"

7 8
	ipld "github.com/ipld/go-ipld-prime"

Eric Myhre's avatar
Eric Myhre committed
9 10 11 12
	wish "github.com/warpfork/go-wish"
)

func doTemplate(tmplstr string, w io.Writer, data interface{}) {
13 14 15 16 17 18 19 20
	tmpl := template.Must(template.New("").
		Funcs(template.FuncMap{
			// 'ReprKindConst' returns the source-string for "ipld.ReprKind_{{Kind}}".
			"ReprKindConst": func(k ipld.ReprKind) string {
				return "ipld.ReprKind_" + k.String() // happens to be fairly trivial.
			},
		}).
		Parse(wish.Dedent(tmplstr)))
Eric Myhre's avatar
Eric Myhre committed
21 22 23 24
	if err := tmpl.Execute(w, data); err != nil {
		panic(err)
	}
}