| 123456789101112131415161718 |
- package middleware
- import (
- "log/slog"
- "net/http"
- )
- // RequestLogger logs each request with method, path, and raw query string.
- func RequestLogger(logger *slog.Logger, next http.Handler) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- logger.Info("request",
- "method", r.Method,
- "path", r.URL.Path,
- "query", r.URL.RawQuery,
- )
- next.ServeHTTP(w, r)
- })
- }
|