From efc3e1735b04aac92bec1ab934cdb06d0e2b662a Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Thu, 3 Feb 2022 10:34:57 +0100 Subject: [PATCH] Fix bug with global scope of iteration variable --- routes.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/routes.go b/routes.go index 71eac7d..4467253 100644 --- a/routes.go +++ b/routes.go @@ -22,7 +22,8 @@ type Route struct { func setupRoutes(router *mux.Router, routes []Route) { for _, route := range routes { - router.HandleFunc(route.Route, func(rw http.ResponseWriter, r *http.Request) { + _route := route + router.HandleFunc(_route.Route, func(rw http.ResponseWriter, r *http.Request) { conf, err := config.GetUIConfig(r) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) @@ -41,13 +42,13 @@ func setupRoutes(router *mux.Router, routes []Route) { infos["admin"] = false } - infos = route.Setup(infos, r) + infos = _route.Setup(infos, r) if id, ok := infos["id"]; ok { - route.Title = strings.Replace(route.Title, "", id.(string), 1) + _route.Title = strings.Replace(_route.Title, "", id.(string), 1) } - templates.Render(rw, r, route.Template, &templates.Page{ - Title: route.Title, + templates.Render(rw, r, _route.Template, &templates.Page{ + Title: _route.Title, Config: conf, Infos: infos, FilterPresets: buildFilterPresets(r.URL.Query()),