18 lines
379 B
Go
18 lines
379 B
Go
package httpapi
|
|
|
|
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()))
|
|
}
|
|
}
|