|
@@ -2,8 +2,11 @@ package response
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"hongze/hongze_yb/global"
|
|
|
+ "hongze/hongze_yb/utils"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -15,23 +18,33 @@ var (
|
|
|
)
|
|
|
|
|
|
type ResultData struct {
|
|
|
- Code int `json:"code" description:"状态码"`
|
|
|
- Msg string `json:"msg" description:"提示信息"`
|
|
|
- Data interface{} `json:"data" description:"返回数据"`
|
|
|
+ Code int `json:"code" description:"状态码"`
|
|
|
+ Msg string `json:"msg" description:"提示信息"`
|
|
|
+ Data interface{} `json:"data" description:"返回数据"`
|
|
|
+ ErrMsg string `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
|
|
|
}
|
|
|
|
|
|
func result(code int, resultData ResultData, c *gin.Context) {
|
|
|
jsonByte, _ := json.Marshal(resultData)
|
|
|
- global.LOG.Debug("resultData:", string(jsonByte))
|
|
|
+ token := c.Request.Header.Get("Authorization")
|
|
|
+ if token == "" {
|
|
|
+ token = c.DefaultQuery("authorization", "")
|
|
|
+ if token == "" {
|
|
|
+ token = c.DefaultQuery("Authorization", "")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logSlice := make([]string, 0)
|
|
|
+ logSlice = append(logSlice, fmt.Sprint("Url:", c.Request.RequestURI))
|
|
|
+ logSlice = append(logSlice, fmt.Sprint("Token:", token))
|
|
|
+ logSlice = append(logSlice, fmt.Sprint("resultData:", string(jsonByte)))
|
|
|
|
|
|
- //测试环境,数据不进行加密
|
|
|
- /*if global.CONFIG.Serve.RunMode == "debug" {
|
|
|
- c.JSON(code, resultData)
|
|
|
- } else {
|
|
|
- responseResult := utils.DesBase64Encrypt(jsonByte)
|
|
|
- c.JSON(code, responseResult)
|
|
|
- }*/
|
|
|
- c.JSON(code, resultData)
|
|
|
+ //记录错误日志
|
|
|
+ if resultData.ErrMsg != "" {
|
|
|
+ logSlice = append(logSlice, fmt.Sprint("ErrMsg:", resultData.ErrMsg))
|
|
|
+ }
|
|
|
+ global.LOG.Info(strings.Join(logSlice, ";"))
|
|
|
+ encryptResult := utils.DesBase64Encrypt(jsonByte)
|
|
|
+ c.JSON(code, string(encryptResult))
|
|
|
c.Abort()
|
|
|
}
|
|
|
|
|
@@ -93,11 +106,12 @@ func CustomData(code int, msg string, data interface{}, c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
// TokenError token异常
|
|
|
-func TokenError(data interface{}, message string, c *gin.Context) {
|
|
|
+func TokenError(data interface{}, message, errMsg string, c *gin.Context) {
|
|
|
resultData := ResultData{
|
|
|
- Code: TOKEN_ERROR_CODE,
|
|
|
- Msg: message,
|
|
|
- Data: data,
|
|
|
+ Code: TOKEN_ERROR_CODE,
|
|
|
+ Msg: message,
|
|
|
+ Data: data,
|
|
|
+ ErrMsg: errMsg,
|
|
|
}
|
|
|
result(200, resultData, c)
|
|
|
}
|