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