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) } }