From d7ce7860bf47ad1f51a44a9705eb0dbf1825eb66 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 27 Mar 2023 17:57:19 +0200 Subject: Pass appdata directory by argument Passing this as part of the configuration file is not flexible. With args it can be easily tweaked for the debug use case while the default path for production is included in the argument parsing. --- main.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 35bacc1..3264134 100644 --- a/main.go +++ b/main.go @@ -15,10 +15,11 @@ import ( "text/template" ) +var appdata string; + type RuntimeConfig struct { Devices DevicesConfig Web WebConfig - Appdata string } type DevicesConfig struct { @@ -33,9 +34,9 @@ type WebConfig struct { func main() { configPath := parseFlags() c := parseConfig(configPath) - http.HandleFunc("/", index(c.Devices, c.Appdata)) + http.HandleFunc("/", index(c.Devices, appdata)) http.HandleFunc("/api", api()) - http.HandleFunc("/webiot.css", css(c.Appdata)) + http.HandleFunc("/webiot.css", css(appdata)) fmt.Printf("Serving at http://%s\n", c.Web.Listen) log.Fatal(http.ListenAndServe(c.Web.Listen.String(), nil)) } @@ -47,6 +48,8 @@ func parseFlags() string { flag.StringVar(&r, "c", "/etc/webiot/config.json", "path to configuration file") + flag.StringVar(&appdata, "a", "/usr/share/webiot", + "path to static application data") flag.Parse() return r -- cgit v1.2.3-70-g09d2