优化response结构
优化日志writer
This commit is contained in:
1 parent
792c8874aa
commit
128739f097
7 files changed
+32
-25
No files matched your search
+6
-6
@@ -1,13 +1,13 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
pbErrors "github.com/go-admin-team/go-admin-core/errors"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
// 代码
|
||||
Code int `json:"code" example:"200"`
|
||||
pbErrors.Error
|
||||
// 数据集
|
||||
Data interface{} `json:"data"`
|
||||
// 消息
|
||||
Msg string `json:"msg"`
|
||||
RequestId string `json:"requestId"`
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
@@ -22,7 +22,7 @@ func (res *Response) ReturnOK() *Response {
|
||||
return res
|
||||
}
|
||||
|
||||
func (res *Response) ReturnError(code int) *Response {
|
||||
func (res *Response) ReturnError(code int32) *Response {
|
||||
res.Code = code
|
||||
return res
|
||||
}
|
||||
+5
-5
@@ -2,16 +2,16 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go-admin/common/log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"go-admin/common/log"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
// 失败数据处理
|
||||
func Error(c *gin.Context, code int, err error, msg string) {
|
||||
func Error(c *gin.Context, code int32, err error, msg string) {
|
||||
msgID := tools.GenerateMsgIDFromContext(c)
|
||||
var res Response
|
||||
if err != nil {
|
||||
@@ -27,7 +27,7 @@ func Error(c *gin.Context, code int, err error, msg string) {
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
c.Set("result",string(jsonStr))
|
||||
c.Set("result", string(jsonStr))
|
||||
c.AbortWithStatusJSON(http.StatusOK, Return)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func OK(c *gin.Context, data interface{}, msg string) {
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
c.Set("result",string(jsonStr))
|
||||
c.Set("result", string(jsonStr))
|
||||
c.AbortWithStatusJSON(http.StatusOK, Return)
|
||||
}
|
||||
|
||||
@@ -69,6 +69,6 @@ func Custum(c *gin.Context, data gin.H) {
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
c.Set("result",string(jsonStr))
|
||||
c.Set("result", string(jsonStr))
|
||||
c.AbortWithStatusJSON(http.StatusOK, Return)
|
||||
}
|
||||
Reference in new issue
Block a user