diff options
author | xengineering <me@xengineering.eu> | 2022-05-16 18:55:08 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-05-16 18:55:08 +0200 |
commit | 96e66b41169a005613fe45f47bb7d1d92950a10f (patch) | |
tree | ecfe5679b4b7c67b77d9367f37e6e6fe94c6cbd2 /main.go | |
parent | 0344477b6014ca879d11934ef2d6fbd8a4c290c3 (diff) | |
download | webiot-96e66b41169a005613fe45f47bb7d1d92950a10f.tar webiot-96e66b41169a005613fe45f47bb7d1d92950a10f.tar.zst webiot-96e66b41169a005613fe45f47bb7d1d92950a10f.zip |
Introduce appdata configuration option
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") |