all repos — homestead @ 8267148e988f22647aa735652dafd06c692b047f

Code for my website

simplify analytics middleware

Alan Pearce
commit

8267148e988f22647aa735652dafd06c692b047f

parent

6917fd4d076a49c7d3c2ca6db4041f5f28550e4f

2 files changed, 14 insertions(+), 16 deletions(-)

changed files
M domain/analytics/middleware.godomain/analytics/middleware.go
@@ -21,23 +21,21 @@
return key, ok } -func CounterMiddleware(counter Counter) func(http.Handler) http.Handler { - return func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - rw := sharedhttp.NewStatusCapturingResponseWriter(w) +func CounterMiddleware(counter Counter, next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + rw := sharedhttp.NewStatusCapturingResponseWriter(w) - next.ServeHTTP(rw, r) + next.ServeHTTP(rw, r) - title, ok := GetTitle(r) - if !ok { - if rw.Status >= 201 { - title = http.StatusText(rw.Status) - } + title, ok := GetTitle(r) + if !ok { + if rw.Status >= 201 { + title = http.StatusText(rw.Status) } + } - if rw.Status <= 299 { - counter.Count(r, title) - } - }) - } + if rw.Status <= 299 { + counter.Count(r, title) + } + }) }
M domain/web/website.godomain/web/website.go
@@ -198,7 +198,7 @@
mux.HandleFunc("/style.css", staticHandler) } - website.Handler = analytics.CounterMiddleware(website.counter)(mux) + website.Handler = analytics.CounterMiddleware(website.counter, mux) return website, nil }