Add static files and HTML templates for web UI
Embedded Tailwind CSS and login/generator templates. Self-contained with no external dependencies.
This commit is contained in:
32
internal/templates/templates.go
Normal file
32
internal/templates/templates.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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)
|
||||
}
|
||||
Reference in New Issue
Block a user