Last active
November 24, 2023 12:35
-
-
Save febriliankr/fe89ba47cc4efbec2542c74eb21faa45 to your computer and use it in GitHub Desktop.
Go code for generating HTML with template and data
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
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