From 94701dfaa4bf7041361cccccc12d45b062746c21 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Mon, 18 May 2020 20:22:19 +0200 Subject: Embed templates in binary --- internal/port/main.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'internal') diff --git a/internal/port/main.go b/internal/port/main.go index fe85ba4..b233012 100644 --- a/internal/port/main.go +++ b/internal/port/main.go @@ -250,25 +250,17 @@ func ListenAndServe(bind, startpagefile string, robotsfile string, robotsdebug b // - var templates *template.Template + tplBox := packr.New("templates", "./internal/port/tpl") - var allFiles []string - files, err := ioutil.ReadDir("./internal/port/tpl") - if err != nil { - return err - } - for _, file := range files { - filename := file.Name() + templates := template.New("main.html").Funcs(funcMap) + + for _, filename := range tplBox.List() { if strings.HasSuffix(filename, ".html") { - allFiles = append(allFiles, "./internal/port/tpl/"+filename) + tplStr, _ := tplBox.FindString(filename) + templates, _ = templates.New(filename).Parse(tplStr) } } - templates, err = template.New("main.html").Funcs(funcMap).ParseFiles(allFiles...) - if err != nil { - return err - } - // startpageTpl := templates.Lookup("startpage.html") -- cgit v1.2.3-70-g09d2