24 lines
473 B
Go
24 lines
473 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"net/http"
|
|
)
|
|
|
|
func LoggingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler {
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
logger.LogAttrs(
|
|
context.Background(),
|
|
slog.LevelInfo,
|
|
"Incoming request",
|
|
slog.String("method", r.Method),
|
|
slog.String("path", r.URL.String()),
|
|
)
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
}
|