Browse Source

Switch embed variables to embed.FS

develop
PrivateGER 3 years ago
parent
commit
4742b42ad0
No known key found for this signature in database GPG Key ID: B9918E382ED08059
  1. 50
      PageHandlers/Templates.go

50
PageHandlers/Templates.go

@ -1,58 +1,20 @@
package PageHandlers
import (
"embed"
_ "embed"
"fmt"
"html/template"
)
//go:embed templates/index.html
var indexTmplSource string
//go:embed templates/view.html
var viewTmplSource string
//go:embed templates/search.html
var searchTmplSource string
//go:embed templates/base.html
var baseTmplSource string
//go:embed templates
var templateFS embed.FS
var tmpl map[string]*template.Template
func init() {
tmpl = make(map[string]*template.Template)
var err error
tmpl["index.html"] = template.New("index.html")
tmpl["index.html"], err = tmpl["index.html"].Parse(baseTmplSource)
if err != nil {
fmt.Println(err)
}
tmpl["index.html"], err = tmpl["index.html"].Parse(indexTmplSource)
if err != nil {
fmt.Println(err)
}
fmt.Println(tmpl["index.html"].Name())
tmpl["search.html"] = template.New("search.html")
tmpl["search.html"], err = tmpl["search.html"].Parse(searchTmplSource)
if err != nil {
fmt.Println(err)
}
tmpl["search.html"], err = tmpl["search.html"].Parse(baseTmplSource)
if err != nil {
fmt.Println(err)
}
tmpl["view.html"] = template.New("view.html")
tmpl["view.html"], err = tmpl["view.html"].Parse(viewTmplSource)
if err != nil {
fmt.Println(err)
}
tmpl["view.html"], err = tmpl["view.html"].Parse(baseTmplSource)
if err != nil {
fmt.Println(err)
}
tmpl["index.html"] = template.Must(template.ParseFS(templateFS, "templates/index.html", "templates/base.html"))
tmpl["search.html"] = template.Must(template.ParseFS(templateFS, "templates/search.html", "templates/base.html"))
tmpl["view.html"] = template.Must(template.ParseFS(templateFS, "templates/view.html", "templates/base.html"))
}

Loading…
Cancel
Save