extract counter as middleware
1 file changed, 5 insertions(+), 4 deletions(-)
changed files
M domain/web/mux.go → domain/web/mux.go
@@ -7,6 +7,7 @@ "regexp" "slices" "strings" + "alin.ovh/homestead/domain/analytics" calendar "alin.ovh/homestead/domain/calendar/templates" "alin.ovh/homestead/domain/web/server" "alin.ovh/homestead/domain/web/templates"@@ -34,7 +35,7 @@ urlPath = "/go" + r.URL.Path } urlPath, shouldRedirect := website.reader.CanonicalisePath(urlPath) if shouldRedirect { - website.counter.Count(r, "302") + analytics.WithCountKey(r, "302") http.Redirect(w, r, urlPath, http.StatusFound) return nil@@ -46,11 +47,11 @@ return ihttp.InternalServerError("Error reading file", err) } if file == nil { - website.counter.Count(r, "404") + analytics.WithCountKey(r, "404") return ihttp.NotFound("File not found") } - website.counter.Count(r, file.Title) + analytics.WithCountKey(r, file.Title) w.Header().Add("ETag", file.Etag) w.Header().Add("Vary", "Accept-Encoding") if file.StyleHash != "" {@@ -76,7 +77,7 @@ return nil } func (website *Website) Calendar(w http.ResponseWriter, r *http.Request) ihttp.Error { - website.counter.Count(r, "Calendar") + analytics.WithCountKey(r, "Calendar") err := calendar.CalendarPage(*website.siteSettings, templates.PageSettings{ Title: "Calendar", TitleAttrs: templates.Attrs{},