修复响应完成时间未设置的问题

This commit is contained in:
白茶清欢 2024-08-17 20:07:48 +08:00
parent 29bcf44ec9
commit ce8feaa98b

View File

@ -54,6 +54,8 @@ 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
@ -61,7 +63,6 @@ func Send(ctx *gin.Context, code any, httpCode int, data any) {
// 设置数据已发送的标识 // 设置数据已发送的标识
defer ctx.Set(hasSendResponseFlag, true) defer ctx.Set(hasSendResponseFlag, true)
responseConfig := define.GetHttpHandleConfig() responseConfig := define.GetHttpHandleConfig()
finishRequestTime := time.Now().UnixMilli()
responseData := map[string]any{ responseData := map[string]any{
responseConfig.ResponseCodeField: code, responseConfig.ResponseCodeField: code,
responseConfig.ResponseMessageField: exception.GetMessage(code), responseConfig.ResponseMessageField: exception.GetMessage(code),