From 4d2f729a2f65a8d645d83bd857d4b0766c49a887 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 25 Mar 2024 20:28:51 +0100 Subject: Directly implement HTTP handler for / There is no reason anymore to work with a closure here. This commit makes the code more readable. --- main.go | 14 ++++++-------- 1 file 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 } } -- cgit v1.2.3-70-g09d2