修复响应完成时间未设置的问题
This commit is contained in:
parent
ce8feaa98b
commit
195e391235
@ -54,12 +54,11 @@ func Success(ctx *gin.Context, data any) {
|
|||||||
func Send(ctx *gin.Context, code any, httpCode int, data any) {
|
func Send(ctx *gin.Context, code any, httpCode int, data any) {
|
||||||
// 设置请求是否成功的标识
|
// 设置请求是否成功的标识
|
||||||
ctx.Set(define.GetHttpHandleConfig().RequestIsSuccessField, fmt.Sprintf("%v", code) == fmt.Sprintf("%v", successBusinessCode))
|
ctx.Set(define.GetHttpHandleConfig().RequestIsSuccessField, fmt.Sprintf("%v", code) == fmt.Sprintf("%v", successBusinessCode))
|
||||||
finishRequestTime := time.Now().UnixMilli()
|
|
||||||
ctx.Set(define.GetHttpHandleConfig().FinishRequestTimeField, finishRequestTime)
|
|
||||||
if ctx.GetBool(hasSendResponseFlag) {
|
if ctx.GetBool(hasSendResponseFlag) {
|
||||||
// 已经发送过数据, 后面在发送数据, 不执行
|
// 已经发送过数据, 后面在发送数据, 不执行
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
finishRequestTime := time.Now().UnixMilli()
|
||||||
// 设置数据已发送的标识
|
// 设置数据已发送的标识
|
||||||
defer ctx.Set(hasSendResponseFlag, true)
|
defer ctx.Set(hasSendResponseFlag, true)
|
||||||
responseConfig := define.GetHttpHandleConfig()
|
responseConfig := define.GetHttpHandleConfig()
|
||||||
@ -68,7 +67,7 @@ func Send(ctx *gin.Context, code any, httpCode int, data any) {
|
|||||||
responseConfig.ResponseMessageField: exception.GetMessage(code),
|
responseConfig.ResponseMessageField: exception.GetMessage(code),
|
||||||
responseConfig.ResponseTraceIDField: ctx.GetString(responseConfig.ResponseTraceIDField),
|
responseConfig.ResponseTraceIDField: ctx.GetString(responseConfig.ResponseTraceIDField),
|
||||||
responseConfig.ResponseDataField: data,
|
responseConfig.ResponseDataField: data,
|
||||||
responseConfig.HandleRequestCostField: finishRequestTime - ctx.GetTime(responseConfig.StartRequestTimeField).UnixMilli(),
|
responseConfig.HandleRequestCostField: finishRequestTime - ctx.GetInt64(responseConfig.StartRequestTimeField),
|
||||||
}
|
}
|
||||||
// 记录完成时间
|
// 记录完成时间
|
||||||
ctx.Set(responseConfig.FinishRequestTimeField, finishRequestTime)
|
ctx.Set(responseConfig.FinishRequestTimeField, finishRequestTime)
|
||||||
|
Loading…
Reference in New Issue
Block a user