XinYeYouKu/app/http/middlewares/metric.go

23 lines
421 B
Go
Raw Permalink Normal View History

2024-06-07 18:24:56 +08:00
package middlewares
import (
"time"
"qteam/app/http/metric"
"github.com/gin-gonic/gin"
)
func CollectMetric() gin.HandlerFunc {
return func(ctx *gin.Context) {
start := time.Now()
ctx.Next()
dur := time.Now().Sub(start).Milliseconds()
metric.AddAllReqCount(ctx.Request)
metric.CollectAllReqCostTime(ctx.Request, dur)
metric.AddReqCount(ctx.Request)
metric.CollectReqCostTime(ctx.Request, dur)
}
}