diff options
author | Feuerfuchs <git@feuerfuchs.dev> | 2020-05-18 20:22:19 +0200 |
---|---|---|
committer | Feuerfuchs <git@feuerfuchs.dev> | 2020-05-18 20:22:19 +0200 |
commit | 94701dfaa4bf7041361cccccc12d45b062746c21 (patch) | |
tree | 879f41349da5add5708dc49c1e8226597f24e58c | |
parent | Improved Gemini support (diff) | |
download | gopherproxy-94701dfaa4bf7041361cccccc12d45b062746c21.tar.gz gopherproxy-94701dfaa4bf7041361cccccc12d45b062746c21.tar.bz2 gopherproxy-94701dfaa4bf7041361cccccc12d45b062746c21.zip |
Embed templates in binary
-rw-r--r-- | internal/port/main.go | 20 |
1 files changed, 6 insertions, 14 deletions
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 | |||
250 | 250 | ||
251 | // | 251 | // |
252 | 252 | ||
253 | var templates *template.Template | 253 | tplBox := packr.New("templates", "./internal/port/tpl") |
254 | 254 | ||
255 | var allFiles []string | 255 | templates := template.New("main.html").Funcs(funcMap) |
256 | files, err := ioutil.ReadDir("./internal/port/tpl") | 256 | |
257 | if err != nil { | 257 | for _, filename := range tplBox.List() { |
258 | return err | ||
259 | } | ||
260 | for _, file := range files { | ||
261 | filename := file.Name() | ||
262 | if strings.HasSuffix(filename, ".html") { | 258 | if strings.HasSuffix(filename, ".html") { |
263 | allFiles = append(allFiles, "./internal/port/tpl/"+filename) | 259 | tplStr, _ := tplBox.FindString(filename) |
260 | templates, _ = templates.New(filename).Parse(tplStr) | ||
264 | } | 261 | } |
265 | } | 262 | } |
266 | 263 | ||
267 | templates, err = template.New("main.html").Funcs(funcMap).ParseFiles(allFiles...) | ||
268 | if err != nil { | ||
269 | return err | ||
270 | } | ||
271 | |||
272 | // | 264 | // |
273 | 265 | ||
274 | startpageTpl := templates.Lookup("startpage.html") | 266 | startpageTpl := templates.Lookup("startpage.html") |