move middleware
This commit is contained in:
23
internal/middleware/logging.go
Normal file
23
internal/middleware/logging.go
Normal file
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user