reprogl
22 строки · 587.0 Байт
1package middlewares2
3import (4"net/http"5
6"xelbot.com/reprogl/container"7pkghttp "xelbot.com/reprogl/http"8)
9
10func AccessLog(next http.Handler, app *container.Application) http.Handler {11return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {12addr := container.RealRemoteAddress(r)13
14next.ServeHTTP(w, r)15lrw, ok := w.(pkghttp.LogResponseWriter)16if ok {17app.InfoLog.Printf("[%s] %s, %s %d %s\n", r.Method, addr, r.URL.RequestURI(), lrw.Status(), lrw.Duration())18} else {19app.InfoLog.Printf("[%s] %s, %s\n", r.Method, addr, r.URL.RequestURI())20}21})22}
23