templating.go 311 B

1234567891011121314151617181920212223
  1. package utils
  2. import (
  3. "bytes"
  4. "html/template"
  5. )
  6. // HTML return an HTML template
  7. func HTML(filename string, params interface{}) (string, error) {
  8. t, err := template.ParseFiles(filename)
  9. if err != nil {
  10. return "", err
  11. }
  12. buf := new(bytes.Buffer)
  13. t.Execute(buf, params)
  14. return buf.String(), nil
  15. }