summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-03-25 20:28:51 +0100
committerxengineering <me@xengineering.eu>2024-03-25 20:28:51 +0100
commit4d2f729a2f65a8d645d83bd857d4b0766c49a887 (patch)
tree0db828d5479cbe0b73d4fb96a1347dcee9455a9a
parent9f1fc3ca35845a0fe5501f8a56646d6568e89e48 (diff)
downloadwebiot-4d2f729a2f65a8d645d83bd857d4b0766c49a887.tar
webiot-4d2f729a2f65a8d645d83bd857d4b0766c49a887.tar.zst
webiot-4d2f729a2f65a8d645d83bd857d4b0766c49a887.zip
Directly implement HTTP handler for /HEAD0.1.0main
There is no reason anymore to work with a closure here. This commit makes the code more readable.
-rw-r--r--main.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/main.go b/main.go
index 15fcc7a..1362cf1 100644
--- a/main.go
+++ b/main.go
@@ -23,7 +23,7 @@ func main() {
log.Fatal(err)
}
- http.HandleFunc("/", index(config.Devices))
+ http.HandleFunc("/", index)
http.HandleFunc("/api", api)
http.Handle("/static/", http.StripPrefix("/static/",
http.FileServer(http.FS(static))))
@@ -46,13 +46,11 @@ func parseFlags() string {
}
// index() returns a HTTP handler for the index page.
-func index(devices DevicesConfig) func(http.ResponseWriter, *http.Request) {
- return func(w http.ResponseWriter, r *http.Request) {
- err := templates.Execute(w, devices)
- if err != nil {
- http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
- return
- }
+func index(w http.ResponseWriter, r *http.Request) {
+ err := templates.Execute(w, config.Devices)
+ if err != nil {
+ http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
+ return
}
}