From 379450c70fc7febe8d72a0fe19d66e81a8edda86 Mon Sep 17 00:00:00 2001 From: nxshock Date: Sat, 25 Sep 2021 17:21:08 +0500 Subject: [PATCH] Make html templates separate from site files --- main.go | 13 ------------- templates.go | 24 ++++++++++++++++++++++++ {site => templates}/index.htm | 0 3 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 templates.go rename {site => templates}/index.htm (100%) diff --git a/main.go b/main.go index 0379977..d434d61 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,12 @@ package main import ( - "html/template" "log" "net/http" "os" "time" ) -var templates *template.Template func init() { log.SetFlags(0) @@ -36,17 +34,6 @@ func init() { http.DefaultClient.Timeout = 5 * time.Second } -func initTepmplates() error { - var err error - - templates, err = template.ParseFS(siteFS, "site/*.htm") - if err != nil { - return err - } - - return nil -} - func main() { http.HandleFunc("/", handleGenres) http.HandleFunc("/genres", handleGenres) diff --git a/templates.go b/templates.go new file mode 100644 index 0000000..c76bc2f --- /dev/null +++ b/templates.go @@ -0,0 +1,24 @@ +package main + +import ( + "embed" + "html/template" +) + +var templates *template.Template + +//go:embed templates/*.htm +var templatesFS embed.FS + +func initTepmplates() error { + var err error + + templates, err = template.ParseFS(templatesFS, "templates/*.htm") + if err != nil { + return err + } + + templatesFS = embed.FS{} + + return nil +} diff --git a/site/index.htm b/templates/index.htm similarity index 100% rename from site/index.htm rename to templates/index.htm