summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/main.go b/main.go
index 80247e8..6d930b4 100644
--- a/main.go
+++ b/main.go
@@ -16,11 +16,20 @@ var templates *template.Template
func main() {
configPath := parseFlags()
c := parseConfig(configPath)
+
+ var err error
+ templates, err = template.ParseFS(static, "templates/index.html")
+ if err != nil {
+ log.Fatal(err)
+ }
+
http.HandleFunc("/", index(c.Devices))
http.HandleFunc("/api", api)
http.Handle("/static/", http.StripPrefix("/static/",
http.FileServer(http.FS(static))))
+
fmt.Printf("Serving at http://%s\n", c.Web.Listen)
+
log.Fatal(http.ListenAndServe(c.Web.Listen.String(), nil))
}
@@ -38,13 +47,8 @@ func parseFlags() string {
// index() returns a HTTP handler for the index page.
func index(devices DevicesConfig) func(http.ResponseWriter, *http.Request) {
- templates, err := template.ParseFS(static, "templates/index.html")
- if err != nil {
- log.Fatal(err)
- }
-
return func(w http.ResponseWriter, r *http.Request) {
- err = templates.Execute(w, devices)
+ err := templates.Execute(w, devices)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
return