增加使用exception发送响应
This commit is contained in:
parent
9031b9543b
commit
c99cdadd7b
2
go.mod
2
go.mod
@ -2,7 +2,7 @@ module git.zhangdeman.cn/zhangdeman/gin
|
||||
|
||||
go 1.17
|
||||
|
||||
require git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626050013-dce8cafff2c6
|
||||
require git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626052433-f29c21f923fc
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220625151616-cfe1f4c04db4 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -4,6 +4,8 @@ git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626045509-282f54bb736a h1:n9k
|
||||
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/exception v0.0.0-20220626052433-f29c21f923fc h1:cD0sibF3bDr3+qpGmimmuLEqNNFdpY2VDk2+EdSeSYE=
|
||||
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220626052433-f29c21f923fc/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/go.mod h1:YI/XeTmrr9+8dxa4ThPkmNcEE8WHG5pZkKujpSWwIxM=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220625151616-cfe1f4c04db4 h1:uHYTRztH/XEVtr3FLykCf/3LhFQ7zQHnzVAeDyC1huQ=
|
||||
|
@ -52,3 +52,19 @@ func Send(ctx *gin.Context, code interface{}, httpCode int, data interface{}) {
|
||||
func SendWithStatusOK(ctx *gin.Context, code interface{}, data map[string]interface{}) {
|
||||
Send(ctx, code, http.StatusOK, data)
|
||||
}
|
||||
|
||||
// SendWithException 使用exception发送数据
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 13:08 2022/6/26
|
||||
func SendWithException(ctx *gin.Context, e *exception.Exception, data interface{}) {
|
||||
if nil == e {
|
||||
e = exception.NewSuccess(data)
|
||||
}
|
||||
if nil != e.GetData() {
|
||||
Send(ctx, e.GetCode(), e.GetHttpCode(), e.GetData())
|
||||
} else {
|
||||
Send(ctx, e.GetCode(), e.GetHttpCode(), data)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user