Add template function experimental cmd

This commit is contained in:
Lucas Schumacher 2024-08-14 12:32:31 -04:00
parent 9c299bc709
commit 1639dd787f

26
cmd/tplfn/tplfn.go Normal file
View File

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