reprogl
26 строк · 571.0 Байт
1package middlewares2
3import (4"net/http"5
6"xelbot.com/reprogl/container"7pkghttp "xelbot.com/reprogl/http"8"xelbot.com/reprogl/utils/tracking"9)
10
11func Track(next http.Handler, app *container.Application) http.Handler {12return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {13activity := tracking.CreateActivity(r)14next.ServeHTTP(w, r)15
16if activity != nil {17lrw, ok := w.(pkghttp.LogResponseWriter)18if ok {19activity.Status = lrw.Status()20activity.Duration = lrw.Duration()21}22
23go tracking.SaveActivity(activity, app)24}25})26}
27