优化发送响应关于时间的处理
This commit is contained in:
parent
ec91bb7a44
commit
5e1aaaf64e
@ -29,7 +29,7 @@ func InitRequest() gin.HandlerFunc {
|
||||
requestID := getRequestID(ctx, traceID)
|
||||
ctx.Set(define.TraceIDField, traceID)
|
||||
ctx.Set(define.RequestIDField, requestID)
|
||||
ctx.Set(define.StartRequestTimeField, time.Now().UnixNano())
|
||||
ctx.Set(define.StartRequestTimeField, time.Now())
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
|
@ -44,14 +44,14 @@ func Send(ctx *gin.Context, code interface{}, httpCode int, data interface{}) {
|
||||
}
|
||||
// 设置数据已发送的标识
|
||||
defer ctx.Set(hasSendResponseFlag, true)
|
||||
finishRequestTime := time.Now().UnixNano()
|
||||
finishRequestTime := time.Now()
|
||||
responseData := map[string]interface{}{
|
||||
define.ResponseCodeField: code,
|
||||
define.ResponseMessageField: exception.GetMessage(code),
|
||||
define.ResponseTraceIDField: ctx.GetString(define.TraceIDField),
|
||||
define.ResponseRequestIDField: ctx.GetString(define.RequestIDField),
|
||||
define.ResponseDataField: data,
|
||||
define.HandleRequestCostField: (finishRequestTime - ctx.GetInt64(define.StartRequestTimeField)) / 1e6,
|
||||
define.HandleRequestCostField: finishRequestTime.UnixMilli() - ctx.GetTime(define.StartRequestTimeField).UnixMilli(),
|
||||
}
|
||||
// 记录响应数据
|
||||
recordData, _ := json.Marshal(responseData)
|
||||
|
Loading…
Reference in New Issue
Block a user