country-geo-locations/internal/exporter/middleware.go

21 lines
429 B
Go
Raw Normal View History

package exporter
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
)
type Middleware struct {
metrics *Metrics
}
func (m Middleware) handler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
timer := prometheus.NewTimer(m.metrics.metricRequestLatency)
next.ServeHTTP(w, r)
m.metrics.metricRequestsTotal.Inc()
timer.ObserveDuration()
})
}