Embedded Tailwind CSS and login/generator templates. Self-contained with no external dependencies.
33 lines
667 B
Go
33 lines
667 B
Go
// Package templates provides embedded HTML templates for the web UI.
|
|
package templates
|
|
|
|
import (
|
|
"embed"
|
|
"html/template"
|
|
"io"
|
|
"sync"
|
|
)
|
|
|
|
//go:embed *.html
|
|
var files embed.FS
|
|
|
|
//nolint:gochecknoglobals // intentional lazy initialization cache
|
|
var (
|
|
parsed *template.Template
|
|
parseOne sync.Once
|
|
)
|
|
|
|
// Get returns the parsed templates, parsing them on first call.
|
|
func Get() *template.Template {
|
|
parseOne.Do(func() {
|
|
parsed = template.Must(template.ParseFS(files, "*.html"))
|
|
})
|
|
|
|
return parsed
|
|
}
|
|
|
|
// Render renders a template by name to the given writer.
|
|
func Render(w io.Writer, name string, data any) error {
|
|
return Get().ExecuteTemplate(w, name, data)
|
|
}
|