优化response + wrapper
This commit is contained in:
parent
b7abf88670
commit
4dc70ee96b
@ -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()
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user