优化响应数据处理
This commit is contained in:
parent
5b4fb6802a
commit
9031b9543b
2
go.mod
2
go.mod
@ -2,7 +2,7 @@ module git.zhangdeman.cn/zhangdeman/gin
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220625143611-42a85f7b80c3
|
require git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626050013-dce8cafff2c6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220625151616-cfe1f4c04db4 // indirect
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220625151616-cfe1f4c04db4 // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -1,5 +1,9 @@
|
|||||||
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220625143611-42a85f7b80c3 h1:bQh+GCEfdusiirGm/XV7gqt7dkejqnvFxplatBUrSSI=
|
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220625143611-42a85f7b80c3 h1:bQh+GCEfdusiirGm/XV7gqt7dkejqnvFxplatBUrSSI=
|
||||||
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220625143611-42a85f7b80c3/go.mod h1:mIMM/t9BkrKHAcDCmarLCHQhHfWf0/ZjtcqJPboqmSA=
|
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220625143611-42a85f7b80c3/go.mod h1:mIMM/t9BkrKHAcDCmarLCHQhHfWf0/ZjtcqJPboqmSA=
|
||||||
|
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626045509-282f54bb736a h1:n9kssd90WV55PsAWJNjSdAYTtZ6ACrZgiv9TEIcsNdA=
|
||||||
|
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626045509-282f54bb736a/go.mod h1:mIMM/t9BkrKHAcDCmarLCHQhHfWf0/ZjtcqJPboqmSA=
|
||||||
|
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626050013-dce8cafff2c6 h1:+hAz/NpZvdsMZefwiV30bJ8Tzon+Bzs/HWiZi/9SOtc=
|
||||||
|
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626050013-dce8cafff2c6/go.mod h1:mIMM/t9BkrKHAcDCmarLCHQhHfWf0/ZjtcqJPboqmSA=
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f h1:yAxxukVUdSM5wn264el+QiAEB0OBN/5H7Xw9Z6rLzUY=
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f h1:yAxxukVUdSM5wn264el+QiAEB0OBN/5H7Xw9Z6rLzUY=
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f/go.mod h1:YI/XeTmrr9+8dxa4ThPkmNcEE8WHG5pZkKujpSWwIxM=
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f/go.mod h1:YI/XeTmrr9+8dxa4ThPkmNcEE8WHG5pZkKujpSWwIxM=
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220625151616-cfe1f4c04db4 h1:uHYTRztH/XEVtr3FLykCf/3LhFQ7zQHnzVAeDyC1huQ=
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220625151616-cfe1f4c04db4 h1:uHYTRztH/XEVtr3FLykCf/3LhFQ7zQHnzVAeDyC1huQ=
|
||||||
|
@ -31,17 +31,16 @@ func Success(ctx *gin.Context, data map[string]interface{}) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 22:40 2022/6/25
|
// Date : 22:40 2022/6/25
|
||||||
func Send(ctx *gin.Context, code interface{}, httpCode int, data map[string]interface{}) {
|
func Send(ctx *gin.Context, code interface{}, httpCode int, data interface{}) {
|
||||||
e := exception.New(code, httpCode, data)
|
|
||||||
responseData := map[string]interface{}{
|
responseData := map[string]interface{}{
|
||||||
define.ResponseCodeField: e.GetCode(),
|
define.ResponseCodeField: code,
|
||||||
define.ResponseMessageField: e.GetMessage(),
|
define.ResponseMessageField: exception.GetMessage(code),
|
||||||
define.ResponseTraceIDField: ctx.GetString(define.TraceIDField),
|
define.ResponseTraceIDField: ctx.GetString(define.TraceIDField),
|
||||||
define.ResponseRequestIDField: ctx.GetString(define.RequestIDField),
|
define.ResponseRequestIDField: ctx.GetString(define.RequestIDField),
|
||||||
define.ResponseDataField: data,
|
define.ResponseDataField: data,
|
||||||
define.HandleRequestCostField: (time.Now().UnixNano() - ctx.GetInt64(define.StartRequestTimeField)) / 1e9,
|
define.HandleRequestCostField: (time.Now().UnixNano() - ctx.GetInt64(define.StartRequestTimeField)) / 1e9,
|
||||||
}
|
}
|
||||||
responseException := exception.New(e.GetCode(), e.GetHttpCode(), responseData)
|
responseException := exception.New(code, httpCode, responseData)
|
||||||
ctx.JSON(responseException.GetHttpCode(), responseException.GetData())
|
ctx.JSON(responseException.GetHttpCode(), responseException.GetData())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user