Fix: sse changes

This commit is contained in:
Grail Finder
2025-05-10 09:01:51 +03:00
parent 2f4891473b
commit 416cc63ec0
6 changed files with 44 additions and 31 deletions

View File

@ -11,29 +11,16 @@ import (
"time"
)
// responseWriterWrapper wraps http.ResponseWriter to capture status code
type responseWriterWrapper struct {
http.ResponseWriter
status int
}
func (w *responseWriterWrapper) WriteHeader(status int) {
w.status = status
w.ResponseWriter.WriteHeader(status)
}
// LogRequests logs all HTTP requests with method, path and duration
func LogRequests(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
// Wrap response writer to capture status code
ww := &responseWriterWrapper{ResponseWriter: w}
next.ServeHTTP(ww, r)
next.ServeHTTP(w, r)
duration := time.Since(start)
log.Debug("request completed",
"method", r.Method,
"path", r.URL.RequestURI(),
"status", ww.status,
"duration", duration.String(),
)
})