Commit a3b2e002 by yemin

提供不带事务返回封装的方法

parent ab097e5d
...@@ -49,6 +49,15 @@ func FailAndMsg(c *gin.Context, subCode, subMsg string) { ...@@ -49,6 +49,15 @@ func FailAndMsg(c *gin.Context, subCode, subMsg string) {
logEnd(c, resp) logEnd(c, resp)
} }
// FailAndMsgNoTx 不带事务
func FailAndMsgNoTx(c *gin.Context, subCode, subMsg string) {
resp := ServerResponse{Code: BusinessError, Msg: "业务错误", SubCode: subCode, SubMsg: subMsg}
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
}
// Success 有事务的用这个
func Success(c *gin.Context) { func Success(c *gin.Context) {
db.Commit() db.Commit()
resp := response(OK) resp := response(OK)
...@@ -57,6 +66,15 @@ func Success(c *gin.Context) { ...@@ -57,6 +66,15 @@ func Success(c *gin.Context) {
logEnd(c, resp) logEnd(c, resp)
} }
// SuccessNoTx 不带事务提交
func SuccessNoTx(c *gin.Context) {
resp := response(OK)
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
}
// SuccessData 有事务的用这个
func SuccessData(c *gin.Context, data interface{}) { func SuccessData(c *gin.Context, data interface{}) {
db.Commit() db.Commit()
resp := ServerDataResponse{response(OK), data} resp := ServerDataResponse{response(OK), data}
...@@ -65,6 +83,14 @@ func SuccessData(c *gin.Context, data interface{}) { ...@@ -65,6 +83,14 @@ func SuccessData(c *gin.Context, data interface{}) {
logEnd(c, resp) logEnd(c, resp)
} }
// SuccessDataNoTx 不带事务提交
func SuccessDataNoTx(c *gin.Context, data interface{}) {
resp := ServerDataResponse{response(OK), data}
c.JSON(http.StatusOK, resp)
c.Abort()
logEnd(c, resp)
}
func SuccessString(c *gin.Context, data string) { func SuccessString(c *gin.Context, data string) {
c.String(http.StatusOK, data) c.String(http.StatusOK, data)
c.Abort() c.Abort()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment