Cannot pass Prometheus midware into httprouter
endpoint definitions.
I'm trying to add a Prometheus midware into our endpoint implementation. But our endpoint are using a third party mux
package called httprouter
. Then when I tried to add this midware into existing code base, I cannot find a good way to integrate both together.
router := httprouter.New()
router.GET("/hello", r.Hello)
func (r configuration) Hello(w http.ResponseWriter, req *http.Request, ps httprouter.Params)
func InstrumentHandlerFunc(name string, handler http.HandlerFunc) http.HandlerFunc {
counter := prometheus.NewCounterVec(
do something...
)
duration := prometheus.NewHistogramVec(
do something...
)
return promhttp.InstrumentHandlerDuration(duration,
promhttp.InstrumentHandlerCounter(counter, handler))
}
My problem is I can not pass my prometheus handle to that httprouter endpoint function as parameter
Below is what I want to do:
func InstrumentHandlerFunc(name string, handler httprouter.Handle) httprouter.Handel {
}
router.Get("/hello", InstrumentHandlerFunc("/hello", r.Hello))
you can use like this.