initial commit

This commit is contained in:
TakuyaYagam1 committed 2026-10-05 14:23:31 +03:00
commit 88c14b627e
224 files changed
+17204

No files matched your search

@@ -0,0 +1,23 @@
package middleware
import (
"net/http"
"time"
"github.com/felixge/httpsnoop"
"github.com/go-chi/chi/v5"
)
type RequestMetrics interface {
ObserveRequest(method, route string, status int, duration time.Duration)
}
func CollectMetrics(metrics RequestMetrics) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
captured := httpsnoop.CaptureMetrics(next, w, r)
route := chi.RouteContext(r.Context()).RoutePattern()
metrics.ObserveRequest(r.Method, route, captured.Code, captured.Duration)
})
}
}