Commit 025e4980 by zhengqiuyun86

初始化

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