响应数据时,增加记录完成请求时间
This commit is contained in:
parent
a2cf256380
commit
adfea6fb4f
@ -33,16 +33,19 @@ func Success(ctx *gin.Context, data interface{}) {
|
||||
//
|
||||
// Date : 22:40 2022/6/25
|
||||
func Send(ctx *gin.Context, code interface{}, httpCode int, data interface{}) {
|
||||
finishRequestTime := time.Now().UnixNano()
|
||||
responseData := map[string]interface{}{
|
||||
define.ResponseCodeField: code,
|
||||
define.ResponseMessageField: exception.GetMessage(code),
|
||||
define.ResponseTraceIDField: ctx.GetString(define.TraceIDField),
|
||||
define.ResponseRequestIDField: ctx.GetString(define.RequestIDField),
|
||||
define.ResponseDataField: data,
|
||||
define.HandleRequestCostField: (time.Now().UnixNano() - ctx.GetInt64(define.StartRequestTimeField)) / 1e9,
|
||||
define.HandleRequestCostField: (finishRequestTime - ctx.GetInt64(define.StartRequestTimeField)) / 1e6,
|
||||
}
|
||||
// 记录响应数据
|
||||
recordData, _ := json.Marshal(responseData)
|
||||
// 记录完成时间
|
||||
ctx.Set(define.FinishRequestTimeField, finishRequestTime)
|
||||
ctx.Set(define.RecordResponseDataField, string(recordData))
|
||||
responseException := exception.New(code, httpCode, responseData)
|
||||
ctx.JSON(responseException.GetHttpCode(), responseException.GetData())
|
||||
|
Loading…
Reference in New Issue
Block a user