package template import ( "html/template" "io/ioutil" ) func LoadHTMLTemplate(filename string, funcMap ...template.FuncMap) (*template.Template, error) { var ( tpl *template.Template err error ) content, err := ioutil.ReadFile(filename) if err != nil { return nil, err } if len(funcMap) > 0 { tpl, err = template.New(filename).Funcs(funcMap[0]).Parse(string(content)) if err != nil { return nil, err } } else { tpl, err = template.New(filename).Parse(string(content)) if err != nil { return nil, err } } return tpl, nil }