Replace bindata by embed
This commit is contained in:
parent
6fddff0b9c
commit
b197fcd9af
5 changed files with 50 additions and 70 deletions
28
static.go
28
static.go
|
|
@ -1,18 +1,34 @@
|
|||
package main
|
||||
|
||||
//go:generate go-bindata -ignore "\\.go|\\.less" -pkg "main" -o "bindata.go" static/...
|
||||
//go:generate go fmt bindata.go
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed all:static
|
||||
var assets embed.FS
|
||||
|
||||
func displayTmpl(w http.ResponseWriter, page string, vars map[string]interface{}) {
|
||||
data := MustAsset("static/" + page)
|
||||
data, err := assets.ReadFile("static/" + page)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to find %q: %s", page, err.Error())
|
||||
}
|
||||
|
||||
footer, err := assets.ReadFile("static/footer.html")
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to find %q: %s", "footer.html", err.Error())
|
||||
}
|
||||
|
||||
header, err := assets.ReadFile("static/header.html")
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to find %q: %s", "header.html", err.Error())
|
||||
}
|
||||
|
||||
tpl := template.Must(template.New("page").Parse(string(data)))
|
||||
tpl.New("footer.html").Parse(string(MustAsset("static/footer.html")))
|
||||
tpl.New("header.html").Parse(string(MustAsset("static/header.html")))
|
||||
tpl.New("footer.html").Parse(string(footer))
|
||||
tpl.New("header.html").Parse(string(header))
|
||||
tpl.ExecuteTemplate(w, "page", vars)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue