Skip to content

Instantly share code, notes, and snippets.

@febriliankr
Last active November 24, 2023 12:35
Show Gist options
  • Save febriliankr/fe89ba47cc4efbec2542c74eb21faa45 to your computer and use it in GitHub Desktop.
Save febriliankr/fe89ba47cc4efbec2542c74eb21faa45 to your computer and use it in GitHub Desktop.
Go code for generating HTML with template and data
func createHTML(templatePath string, htmlData any) (string, error) {
var html string
htmlTemplate, err := template.ParseFiles(templatePath)
if err != nil {
return html, err
}
buf := new(bytes.Buffer)
err = htmlTemplate.Execute(buf, htmlData)
if err != nil {
fmt.Println(err)
return html, err
}
html = buf.String()
html, err = minify.HTML(html)
if err != nil {
return html, err
}
return html, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment