summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/main.go b/main.go
index b70c193..b8fe2e2 100644
--- a/main.go
+++ b/main.go
@@ -11,6 +11,7 @@ import (
"log"
"net/http"
"net/netip"
+ "path/filepath"
"text/template"
)
@@ -24,18 +25,19 @@ type DevicesConfig struct {
}
type WebConfig struct {
- Listen netip.AddrPort
+ Listen netip.AddrPort
+ Templates string
}
// main() contains the control flow of this program.
func main() {
configPath := parseFlags()
- config := parseConfig(configPath)
- http.HandleFunc("/", index(config.Devices))
+ c := parseConfig(configPath)
+ http.HandleFunc("/", index(c.Devices, c.Web.Templates))
http.HandleFunc("/api", api())
http.HandleFunc("/webiot.css", css())
- fmt.Printf("Serving at http://%s\n", config.Web.Listen)
- log.Fatal(http.ListenAndServe(config.Web.Listen.String(), nil))
+ fmt.Printf("Serving at http://%s\n", c.Web.Listen)
+ log.Fatal(http.ListenAndServe(c.Web.Listen.String(), nil))
}
// parseFlags() handles command line interface (CLI) flags.
@@ -71,10 +73,11 @@ func parseConfig(path string) RuntimeConfig {
}
// index() returns a HTTP handler for the index page.
-func index(config DevicesConfig) func(http.ResponseWriter, *http.Request) {
+func index(devices DevicesConfig, templates string) func(http.ResponseWriter, *http.Request) {
// prepare HTML
- html := mustRender("index.html.tmpl", config)
+ path := filepath.Join(templates, "index.html.tmpl")
+ html := mustRender(path, devices)
return func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, html)