Files
isp-gate-service/middleware/metrics_middleware.go
T
2026-11-25 18:34:09 +03:00

32 lines
590 B
Go

package middleware
import (
"isp-gate-service/request"
"time"
"github.com/txix-open/isp-kit/metrics/http_metrics"
)
func Metrics(storage *http_metrics.ServerStorage) Middleware {
return func(next Handler) Handler {
return HandlerFunc(func(ctx *request.Context) error {
pathSchema := ctx.EndpointMeta().PathSchema
if pathSchema == "" {
return next.Handle(ctx)
}
r := ctx.Request()
start := time.Now()
err := next.Handle(ctx)
if err != nil {
return err
}
storage.ObserveDuration(r.Method, pathSchema, time.Since(start))
return nil
})
}
}