package templates import ( "bytes" "fmt" "text/template" ) // FillTemplate takes a template file and an interface specifying the data used by the template file and fills it, returning a string. func FillTemplate(data interface{}, templatePath string) (string, error) { tmpl, err := template.ParseFiles(templatePath) if err != nil { return "", fmt.Errorf("unable to parse template file: %s", err) } var result bytes.Buffer if err := tmpl.Execute(&result, data); err != nil { return "", fmt.Errorf("execute error: %s", err) } return result.String(), nil }