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. --- .gitignore | 1 - Makefile | 8 ++++---- appdata/index.html.tmpl | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ appdata/webiot.css | 1 + config.json | 3 +-- index.html.tmpl | 49 ------------------------------------------------- main.go | 9 ++++++--- webiot.css | 1 - 8 files changed, 61 insertions(+), 60 deletions(-) delete mode 100644 .gitignore create mode 100644 appdata/index.html.tmpl create mode 120000 appdata/webiot.css delete mode 100644 index.html.tmpl delete mode 120000 webiot.css diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3e18ebf..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -private diff --git a/Makefile b/Makefile index e258995..c8d409a 100644 --- a/Makefile +++ b/Makefile @@ -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/appdata/index.html.tmpl b/appdata/index.html.tmpl new file mode 100644 index 0000000..17c67c1 --- /dev/null +++ b/appdata/index.html.tmpl @@ -0,0 +1,49 @@ + + + + + + + + + IoT + + + + + + + + + +
+ +

IoT

+ + {{range .Hs100}} +
+

{{.Name}}

+ + +
+ {{end}} + + + +
+ + + + 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/" + } } diff --git a/index.html.tmpl b/index.html.tmpl deleted file mode 100644 index 17c67c1..0000000 --- a/index.html.tmpl +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - IoT - - - - - - - - - -
- -

IoT

- - {{range .Hs100}} -
-

{{.Name}}

- - -
- {{end}} - - - -
- - - - 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 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 -- cgit v1.2.3-70-g09d2