Created
October 14, 2021 16:37
-
-
Save immannino/ed985b9609ed6d1b1332773614e5f1e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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