diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -18,6 +18,7 @@ import ( type RuntimeConfig struct { Devices DevicesConfig Web WebConfig + Appdata string } type DevicesConfig struct { @@ -26,16 +27,15 @@ type DevicesConfig struct { type WebConfig struct { Listen netip.AddrPort - Templates string } // main() contains the control flow of this program. func main() { configPath := parseFlags() c := parseConfig(configPath) - http.HandleFunc("/", index(c.Devices, c.Web.Templates)) + http.HandleFunc("/", index(c.Devices, c.Appdata)) http.HandleFunc("/api", api()) - http.HandleFunc("/webiot.css", css()) + http.HandleFunc("/webiot.css", css(c.Appdata)) fmt.Printf("Serving at http://%s\n", c.Web.Listen) log.Fatal(http.ListenAndServe(c.Web.Listen.String(), nil)) } @@ -73,10 +73,10 @@ func parseConfig(path string) RuntimeConfig { } // index() returns a HTTP handler for the index page. -func index(devices DevicesConfig, templates string) func(http.ResponseWriter, *http.Request) { +func index(devices DevicesConfig, appdata string) func(http.ResponseWriter, *http.Request) { // prepare HTML - path := filepath.Join(templates, "index.html.tmpl") + path := filepath.Join(appdata, "index.html.tmpl") html := mustRender(path, devices) return func(w http.ResponseWriter, r *http.Request) { @@ -84,10 +84,11 @@ func index(devices DevicesConfig, templates string) func(http.ResponseWriter, *h } } -func css() func(http.ResponseWriter, *http.Request) { +func css(appdata string) func(http.ResponseWriter, *http.Request) { // read CSS file - css := string(mustRead("./libweb/libweb.css")) + path := filepath.Join(appdata, "libweb/libweb.css") + css := string(mustRead(path)) return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/css; charset=utf-8") |