Commit 025e4980 by zhengqiuyun86

初始化

parent 40adad1a
...@@ -17,8 +17,8 @@ import ( ...@@ -17,8 +17,8 @@ import (
type ServerResponse struct { type ServerResponse struct {
Code State `json:"code"` //0为成功,其他都是失败 Code State `json:"code"` //0为成功,其他都是失败
Msg string `json:"msg,omitempty"` //非1000情况下的错误描述 Msg string `json:"msg,omitempty"` //非1000情况下的错误描述
SubCode string `json:"subCode"` SubCode string `json:"subCode,omitempty"`
SubMsg string `json:"subMsg"` SubMsg string `json:"subMsg,omitempty"`
} }
type ServerDataResponse struct { type ServerDataResponse struct {
...@@ -30,8 +30,12 @@ func response(state State) ServerResponse { ...@@ -30,8 +30,12 @@ func response(state State) ServerResponse {
return ServerResponse{Code: state, Msg: state.String()} return ServerResponse{Code: state, Msg: state.String()}
} }
func FailGetWay(c *gin.Context, state State) { func responseSub(state State, subCode, subMsg string) ServerResponse {
resp := response(state) return ServerResponse{Code: state, Msg: state.String(), SubCode: subCode, SubMsg: subMsg}
}
func FailGetWay(c *gin.Context, state State, subCode, subMsg string) {
resp := responseSub(state, subCode, subMsg)
c.JSON(http.StatusBadGateway, resp) c.JSON(http.StatusBadGateway, resp)
c.Abort() c.Abort()
logEnd(c, resp) logEnd(c, resp)
......
...@@ -6,15 +6,7 @@ type State int16 ...@@ -6,15 +6,7 @@ type State int16
const ( const (
BusinessError State = 1001 BusinessError State = 1001
OK State = 1000 OK State = 1000
Illegal1 State = 1 - iota Illegal State = 9000
Illegal2
Illegal3
Illegal4
Illegal5
Illegal6
Illegal7
Illegal8
Illegal9
) )
func (t State) String() string { func (t State) String() string {
...@@ -23,24 +15,8 @@ func (t State) String() string { ...@@ -23,24 +15,8 @@ func (t State) String() string {
return "business error" return "business error"
case OK: case OK:
return "OK" return "OK"
case Illegal1: case Illegal:
return "illegal request(1)" return "非法请求"
case Illegal2:
return "illegal request(2)"
case Illegal3:
return "illegal request(3)"
case Illegal4:
return "illegal request(4)"
case Illegal5:
return "illegal request(5)"
case Illegal6:
return "illegal request(6)"
case Illegal7:
return "illegal request(7)"
case Illegal8:
return "illegal request(8)"
case Illegal9:
return "illegal request(9)"
default: default:
return "unknown" return "unknown"
} }
......
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