diff --git a/index.go b/index.go index de0df7f..f6e2cbb 100644 --- a/index.go +++ b/index.go @@ -6,23 +6,12 @@ import ( "time" ) -var index_template *template.Template - type indexData struct { Time string } func handleRoot(w http.ResponseWriter, r *http.Request) { - //if index_template == nil { - // tmpl, err := template.ParseFiles("templates/index.html") - // if err != nil { - // http.Error(w, "Couldn't parse template file", http.StatusInternalServerError) - // return - // } - // index_template = tmpl - //} - - tmpl, err := template.ParseFiles("templates/index.html") + tmpl, err := template.ParseFS(embed_templates, "templates/index.html") if err != nil { http.Error(w, "Couldn't parse template file", http.StatusInternalServerError) return diff --git a/main.go b/main.go index 394fde9..1ce6e7c 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,15 @@ package main import ( + "embed" "log" "net/http" "os" ) +//go:embed templates +var embed_templates embed.FS + func main() { port := os.Getenv("PORT") if port == "" { @@ -14,9 +18,7 @@ func main() { } http.HandleFunc("/", handleRoot) - http.HandleFunc("/clicked", handleClicked) if err := http.ListenAndServe(":"+port, nil); err != nil { log.Fatal(err) } - } diff --git a/templates/index.html b/templates/index.html index a7cd2cd..fd52410 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,6 +6,7 @@