增加使用exception发送响应

This commit is contained in:
2022-06-26 13:28:31 +08:00
parent 9031b9543b
commit c99cdadd7b
3 changed files with 19 additions and 1 deletions

View File

@ -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)
}
}