diff options
author | xengineering <me@xengineering.eu> | 2023-03-27 17:57:19 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-03-27 17:57:19 +0200 |
commit | d7ce7860bf47ad1f51a44a9705eb0dbf1825eb66 (patch) | |
tree | 49f36a991a4777aa3e6cee4b43e8d83668e4e7dd | |
parent | 5d1d9e09e3fd26228230bb325ca3d5ddf2576070 (diff) | |
download | webiot-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.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | appdata/index.html.tmpl (renamed from index.html.tmpl) | 0 | ||||
l--------- | appdata/webiot.css | 1 | ||||
-rw-r--r-- | config.json | 3 | ||||
-rw-r--r-- | main.go | 9 | ||||
l--------- | webiot.css | 1 |
7 files changed, 12 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3e18ebf..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -private @@ -10,7 +10,7 @@ all: # some recommended options for Go building: # https://wiki.archlinux.org/title/Go_package_guidelines mkdir -p build - go build -o build/$(PROGRAM) main.go hs100.go + go build -o build/$(PROGRAM) *.go clean: rm -rf build @@ -18,11 +18,11 @@ clean: install: all install -Dm 755 build/$(PROGRAM) $(DESTDIR)$(PREFIX)/bin/$(PROGRAM) install -Dm 644 config.json $(DESTDIR)/etc/$(PROGRAM)/config.json - install -Dm 644 index.html.tmpl $(DESTDIR)$(PREFIX)/share/$(PROGRAM)/index.html.tmpl - install -Dm 644 libweb/libweb.css $(DESTDIR)$(PREFIX)/share/$(PROGRAM)/webiot.css + install -Dm 644 appdata/index.html.tmpl $(DESTDIR)$(PREFIX)/share/$(PROGRAM)/index.html.tmpl + install -Dm 644 appdata/webiot.css $(DESTDIR)$(PREFIX)/share/$(PROGRAM)/webiot.css install -Dm 644 systemd/$(PROGRAM).service $(DESTDIR)$(PREFIX)/lib/systemd/system/$(PROGRAM).service install -Dm 644 systemd/$(PROGRAM).sysusers $(DESTDIR)$(PREFIX)/lib/sysusers.d/$(PROGRAM).conf debug: - go run main.go hs100.go -c private/config.json + go run *.go -c config.json -a appdata diff --git a/index.html.tmpl b/appdata/index.html.tmpl index 17c67c1..17c67c1 100644 --- a/index.html.tmpl +++ b/appdata/index.html.tmpl diff --git a/appdata/webiot.css b/appdata/webiot.css new file mode 120000 index 0000000..9dd798c --- /dev/null +++ b/appdata/webiot.css @@ -0,0 +1 @@ +../libweb/libweb.css
\ No newline at end of file diff --git a/config.json b/config.json index 513e364..9366364 100644 --- a/config.json +++ b/config.json @@ -7,6 +7,5 @@ }, "web":{ "listen":"127.0.0.1:9000" - }, - "appdata":"/usr/share/webiot/" + } } @@ -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 diff --git a/webiot.css b/webiot.css deleted file mode 120000 index 7efcff2..0000000 --- a/webiot.css +++ /dev/null @@ -1 +0,0 @@ -libweb/libweb.css
\ No newline at end of file |