You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
440 B
Go
24 lines
440 B
Go
4 years ago
|
package httphandler
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"zero/core/stat"
|
||
|
"zero/core/timex"
|
||
|
)
|
||
|
|
||
|
func MetricHandler(metrics *stat.Metrics) func(http.Handler) http.Handler {
|
||
|
return func(next http.Handler) http.Handler {
|
||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
startTime := timex.Now()
|
||
|
defer func() {
|
||
|
metrics.Add(stat.Task{
|
||
|
Duration: timex.Since(startTime),
|
||
|
})
|
||
|
}()
|
||
|
|
||
|
next.ServeHTTP(w, r)
|
||
|
})
|
||
|
}
|
||
|
}
|