@@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user