Skip to content

Instantly share code, notes, and snippets.

@immannino
Created October 14, 2021 16:37
Show Gist options
  • Select an option

  • Save immannino/ed985b9609ed6d1b1332773614e5f1e7 to your computer and use it in GitHub Desktop.

Select an option

Save immannino/ed985b9609ed6d1b1332773614e5f1e7 to your computer and use it in GitHub Desktop.
package template
import (
"bytes"
"html/template"
)
type HTMLTemplateInterface interface {
Compile(interface{}, string) (bytes.Buffer, error)
}
// HTMLTemplate contains the HTML templates used for PDF content
type HTMLTemplate struct {
Templates *template.Template
}
// App won't start if the system can't parse the templates.
func NewHTMLTemplate() *HTMLTemplate {
return &HTMLTemplate{
Templates: template.Must(template.ParseGlob("./templates/*")),
}
}
func (ht *HTMLTemplate) Compile(data interface{}, name string) (bytes.Buffer, error) {
var b bytes.Buffer
err := ht.Templates.ExecuteTemplate(&b, name, data)
if err != nil {
return *new(bytes.Buffer), err
}
return b, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment