If the type of the map is map[string]interface{}, it can be used with either type of template.
https://play.golang.org/p/-sFMhKOtNN
If you create your own template type, then you can also create your own FuncMap type, and in your own Funcs method, pass it on to the underlying template:
type FuncMap map[string]interface{}
type Template struct{
tmpl interface{}
}
func (t *Template) Funcs(fm FuncMap) *Template {
fmBase := map[string]interface{}(fm)
switch tt := t.tmpl.(type) {
case *htmltemplate.Template:
return Template{tmpl: tt.Funcs(fmBase)}
case *texttemplate.Template:
return Template{tmpl: tt.Funcs(fmBase)}
default:
// this shouldn't happen
panic("unrecognized template type")
}
But you also then have no choice but to wrap every single method that (that you want to also have) returns a *Template, so that it returns your own template type instead. That's why I don't think it's a good idea to create your own Template type.