You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nikita-tokarch-uk/frontend/templates/templates.go

55 lines
929 B

package templates
import (
"bytes"
"embed"
"html/template"
"io/fs"
"github.com/sirupsen/logrus"
)
// Static go-templates source
//go:embed blog.go.tmpl
//go:embed error.go.tmpl
//go:embed index.go.tmpl
var content embed.FS
// List of compiled go-templates
var Templates *template.Template
// Load embeded templates
func init() {
Templates = template.New("")
tmplNames, err := fs.Glob(content, "*.go.tmpl")
if err != nil {
panic(err)
}
buf := bytes.NewBuffer(nil)
for _, name := range tmplNames {
buf.Reset()
tmplContent, err := content.Open(name)
if err != nil {
panic(err)
}
size, err := buf.ReadFrom(tmplContent)
if err != nil {
panic(err)
}
tmpl, err := Templates.New(name).Parse(buf.String())
if err != nil {
panic(err)
}
logrus.Debugf("Found template: %s, size:%d", tmpl.Name(), size)
}
logrus.Debugf("Templates loading complete%s", Templates.DefinedTemplates())
}