summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-03-27 17:57:19 +0200
committerxengineering <me@xengineering.eu>2023-03-27 17:57:19 +0200
commitd7ce7860bf47ad1f51a44a9705eb0dbf1825eb66 (patch)
tree49f36a991a4777aa3e6cee4b43e8d83668e4e7dd /main.go
parent5d1d9e09e3fd26228230bb325ca3d5ddf2576070 (diff)
downloadwebiot-d7ce7860bf47ad1f51a44a9705eb0dbf1825eb66.tar
webiot-d7ce7860bf47ad1f51a44a9705eb0dbf1825eb66.tar.zst
webiot-d7ce7860bf47ad1f51a44a9705eb0dbf1825eb66.zip
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.
Diffstat (limited to 'main.go')
-rw-r--r--main.go9
1 files changed, 6 insertions, 3 deletions
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