package middlewares import ( "net/http" "time" "git.secnex.io/secnex/masterlog" "github.com/go-chi/chi/v5/middleware" ) func LoggerMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { start := time.Now() ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor) next.ServeHTTP(ww, r) masterlog.Info("HTTP Request", map[string]interface{}{ "method": r.Method, "path": r.URL.Path, "status": ww.Status(), "duration": time.Since(start).String(), "host": r.Host, "ip": r.RemoteAddr, }) }) }