Files
web_huangguo2_h5/app/router/html.go
T
谢宇宁andClaude Opus 5.5 0fbdba5ccf Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 11:47:47 +07:00

35 lines
729 B
Go

package router
import (
"html/template"
"io/fs"
"path/filepath"
"strings"
webtpl "videoweb/app/template"
)
func mustHTMLTemplate(funcMap template.FuncMap) *template.Template {
tmpl := template.New("").Funcs(funcMap)
err := fs.WalkDir(webtpl.FS, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
return err
}
if !strings.HasSuffix(strings.ToLower(d.Name()), ".html") {
return nil
}
body, err := webtpl.FS.ReadFile(path)
if err != nil {
return err
}
_, err = tmpl.New(filepath.Base(path)).Parse(string(body))
return err
})
if err != nil {
panic(err)
}
if tmpl.Lookup("index.html") == nil {
panic("embedded html templates are empty")
}
return tmpl
}