diff --git a/cmd/tplfn/tplfn.go b/cmd/tplfn/tplfn.go new file mode 100644 index 0000000..f16c560 --- /dev/null +++ b/cmd/tplfn/tplfn.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "html/template" + "os" +) + +func main() { + tplstr := "hello {{myFunc}}\n" + + fmap := template.FuncMap{} + fmap["myFunc"] = func() (string, error) { + return "world", fmt.Errorf("hi") + } + + tpl, err := template.New("demo").Funcs(fmap).Parse(tplstr) + if err != nil { + panic(fmt.Errorf("Error creating template: %v", err)) + } + + err = tpl.Execute(os.Stdout, nil) + if err != nil { + panic(err) + } +}