http-api-kit/middleware.go

19 lines
379 B
Go
Raw Permalink Normal View History

2024-10-06 14:34:17 +00:00
package httpapi
2024-10-06 14:18:16 +00:00
import (
"fmt"
"log/slog"
"net/http"
"time"
)
type Middleware = func(http.HandlerFunc) http.HandlerFunc
func LoggingMiddleware(f http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
f(w, r)
slog.Info(fmt.Sprintf("%s - %s (%dms)", r.Method, r.URL, time.Now().Sub(start).Milliseconds()))
}
}