From cd8d7388a63d6e8457cbb8b52c3ac533b652f464 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 2 Sep 2020 15:25:34 +0200 Subject: [PATCH] Use go-bindata instead of esc --- .gitignore | 2 +- main.go | 1 - tmpl.go => static.go | 22 ++++++++-------------- 3 files changed, 9 insertions(+), 16 deletions(-) rename tmpl.go => static.go (57%) diff --git a/.gitignore b/.gitignore index bc33b94..7d5152a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ chldapasswd config.json -static.go \ No newline at end of file +bindata.go \ No newline at end of file diff --git a/main.go b/main.go index c36a613..5b9114c 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,5 @@ package main -//go:generate esc -o static.go static import ( "context" "encoding/json" diff --git a/tmpl.go b/static.go similarity index 57% rename from tmpl.go rename to static.go index b984a70..6683f58 100644 --- a/tmpl.go +++ b/static.go @@ -1,25 +1,19 @@ package main +//go:generate go-bindata -ignore "\\.go|\\.less" -pkg "main" -o "bindata.go" static/... +//go:generate go fmt bindata.go + import ( "html/template" "net/http" - "path" ) func displayTmpl(w http.ResponseWriter, page string, vars map[string]interface{}) { - t := template.New("index") - for _, fname := range []string{ - "/static/change.html", - "/static/footer.html", - "/static/header.html", - "/static/login.html", - "/static/lost.html", - "/static/message.html", - "/static/reset.html", - } { - t.New(path.Base(fname)).Parse(FSMustString(false, fname)) - } - t.ExecuteTemplate(w, page, vars) + data := MustAsset("static/" + page) + 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.ExecuteTemplate(w, "page", vars) } func displayTmplError(w http.ResponseWriter, statusCode int, page string, vars map[string]interface{}) {