diff --git a/request/wrapper.go b/request/wrapper.go index 6a05726..b2e4f0d 100644 --- a/request/wrapper.go +++ b/request/wrapper.go @@ -73,3 +73,11 @@ func (wh *wrapperHandle) GetContentType(ctx *gin.Context, defaultVal string) str contentType := strings.ToLower(ctx.ContentType()) return wrapper.TernaryOperator.String(len(contentType) > 0, wrapper.String(contentType), wrapper.String(defaultVal)).Value() } + +func (wh *wrapperHandle) GetResponseBody(ctx *gin.Context, defaultVal string) string { + if nil == ctx { + return defaultVal + } + contentType := strings.ToLower(ctx.ContentType()) + return wrapper.TernaryOperator.String(len(contentType) > 0, wrapper.String(contentType), wrapper.String(defaultVal)).Value() +} diff --git a/response/response.go b/response/response.go index 39916b9..a6d148c 100644 --- a/response/response.go +++ b/response/response.go @@ -8,7 +8,6 @@ package response import ( - "encoding/json" "net/http" "time" @@ -53,11 +52,9 @@ func Send(ctx *gin.Context, code interface{}, httpCode int, data interface{}) { define.ResponseDataField: data, define.HandleRequestCostField: finishRequestTime.UnixMilli() - ctx.GetTime(define.StartRequestTimeField).UnixMilli(), } - // 记录响应数据 - recordData, _ := json.Marshal(responseData) // 记录完成时间 ctx.Set(define.FinishRequestTimeField, finishRequestTime) - ctx.Set(define.RecordResponseDataField, string(recordData)) + ctx.Set(define.RecordResponseDataField, responseData) responseException := exception.New(code, httpCode, responseData) ctx.JSON(responseException.GetHttpCode(), responseException.GetData()) }