1
0
mirror of https://github.com/thebaer/cdr.git synced 2024-11-15 01:31:01 +00:00
cdr/render.go
Matt Baer 16e4510d9d Use Go's embed pkg instead of inline tool
This moves the minimum requirements to Go 1.16 to build this project.
2022-03-30 23:14:32 -04:00

30 lines
669 B
Go

package cdr
import (
_ "embed"
"html/template"
"io"
"io/ioutil"
"log"
)
func Render(m *Mixtape, w io.Writer) error {
mixtapeRawTmpl, err := ioutil.ReadFile("mixtape.tmpl")
if err != nil {
log.Print("Unable to load custom mixtape.tmpl; falling back to default")
mixtapeRawTmpl = defaultMixtapeTmpl
} else {
log.Print("Generating from local mixtape.tmpl")
}
t, err := template.New("mixtape").Parse(string(mixtapeRawTmpl) + string(partsRawTmpl))
if err != nil {
log.Printf("[ERROR] Unable to parse: %v", err)
return err
}
err = t.ExecuteTemplate(w, "mixtape", m)
if err != nil {
log.Printf("[ERROR] Unable to render: %v", err)
}
return nil
}