package web import ( "dwelling-radio/pkg/logging" "embed" "html/template" "net/http" "github.com/Joker/jade" ) var compiledTemplates map[string]*template.Template //go:embed assets var assetsDir embed.FS func Assets() http.FileSystem { return http.FS(assetsDir) } func AssetsGetFile(path string) ([]byte, error) { return assetsDir.ReadFile(path) } //go:embed templates var templatesDir embed.FS func Template(name string) *template.Template { return compiledTemplates[name] } func CompileTemplates(lErr *logging.Logger) { compiledTemplates = make(map[string]*template.Template) indexStr, err := jade.ParseFileFromFileSystem("index.jade", http.FS(templatesDir)) if err != nil { lErr.Fatalln(err) } indexTpl, err := template.New("index").Parse(indexStr) if err != nil { lErr.Fatalln(err) } compiledTemplates["index"] = indexTpl }