提交 9c6e2c69 authored 作者: mooncake9527's avatar mooncake9527

cost

上级 42c85be5
......@@ -248,7 +248,7 @@ func SetVal(ctx context.Context, key string, val interface{}) context.Context {
func AddApiCost(c *gin.Context, appName string, start time.Time) {
cost := c.Writer.Header().Get(KeyCost)
currentCost := fmt.Sprintf("%s:%s", appName, time.Since(start).String())
currentCost := fmt.Sprintf("%s:%s", appName, formatDuration(time.Since(start)))
if cost == "" {
cost = currentCost
} else {
......@@ -257,6 +257,11 @@ func AddApiCost(c *gin.Context, appName string, start time.Time) {
c.Writer.Header().Set(KeyCost, cost)
}
func formatDuration(d time.Duration) string {
ms := float64(d.Nanoseconds()) / 1e6
return fmt.Sprintf("%.2fms", ms)
}
func SetApiCost(ctx context.Context, header map[string][]string) {
if ginCtx, _ := GetGinCtx(ctx); ginCtx != nil && len(header) > 0 {
cost := ""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论