正在显示
5 个修改的文件
包含
41 行增加
和
25 行删除
@@ -12,6 +12,6 @@ RUN mkdir -p $APP_DIR | @@ -12,6 +12,6 @@ RUN mkdir -p $APP_DIR | ||
12 | ADD . $APP_DIR | 12 | ADD . $APP_DIR |
13 | 13 | ||
14 | # Compile the binary and statically link | 14 | # Compile the binary and statically link |
15 | -RUN cd $APP_DIR && CGO_ENABLED=0 go build -mod=vendor -ldflags '-d -w -s' | 15 | +RUN cd $APP_DIR && CGO_ENABLED=0 go build -mod=vendor -ldflags '-d -w -s' -o oppmg |
16 | WORKDIR $APP_DIR | 16 | WORKDIR $APP_DIR |
17 | EXPOSE 8080 | 17 | EXPOSE 8080 |
@@ -7,6 +7,8 @@ import ( | @@ -7,6 +7,8 @@ import ( | ||
7 | serveauth "oppmg/services/auth" | 7 | serveauth "oppmg/services/auth" |
8 | "oppmg/storage/redisdata" | 8 | "oppmg/storage/redisdata" |
9 | 9 | ||
10 | + "github.com/astaxie/beego" | ||
11 | + | ||
10 | "github.com/astaxie/beego/plugins/cors" | 12 | "github.com/astaxie/beego/plugins/cors" |
11 | 13 | ||
12 | "github.com/astaxie/beego/context" | 14 | "github.com/astaxie/beego/context" |
@@ -70,10 +72,13 @@ var AuthToken = func(ctx *context.Context) { | @@ -70,10 +72,13 @@ var AuthToken = func(ctx *context.Context) { | ||
70 | ctx.Output.JSON(msg, false, false) | 72 | ctx.Output.JSON(msg, false, false) |
71 | return | 73 | return |
72 | } | 74 | } |
73 | - if storetoken.AccessToken != accesstoken { | ||
74 | - msg = protocol.NewMesage("10025") | ||
75 | - ctx.Output.JSON(msg, false, false) | ||
76 | - return | 75 | + if beego.BConfig.RunMode == "prod" { |
76 | + //校验是否是单客户端操作 | ||
77 | + if storetoken.AccessToken != accesstoken { | ||
78 | + msg = protocol.NewMesage("10025") | ||
79 | + ctx.Output.JSON(msg, false, false) | ||
80 | + return | ||
81 | + } | ||
77 | } | 82 | } |
78 | ctx.Input.SetData(protocol.HeaderCompanyid, mtoken.CompanyID) | 83 | ctx.Input.SetData(protocol.HeaderCompanyid, mtoken.CompanyID) |
79 | ctx.Input.SetData(protocol.HeaderUserid, mtoken.UID) | 84 | ctx.Input.SetData(protocol.HeaderUserid, mtoken.UID) |
@@ -2,12 +2,12 @@ package protocol | @@ -2,12 +2,12 @@ package protocol | ||
2 | 2 | ||
3 | //RequestPageInfo 分页获取数据 | 3 | //RequestPageInfo 分页获取数据 |
4 | type RequestPageInfo struct { | 4 | type RequestPageInfo struct { |
5 | - PageIndex int `json:"page_index"` | ||
6 | - PageSize int `json:"page_size"` | 5 | + PageIndex int `json:"page"` |
6 | + PageSize int `json:"pageSize"` | ||
7 | } | 7 | } |
8 | 8 | ||
9 | //ResponsePageInfo 分页信息 | 9 | //ResponsePageInfo 分页信息 |
10 | type ResponsePageInfo struct { | 10 | type ResponsePageInfo struct { |
11 | - TotalPage int `json:"total_page"` | ||
12 | - CurrentPage int `json:"current_page"` | 11 | + TotalPage int `json:"totalRow"` |
12 | + CurrentPage int `json:"pageNumber"` | ||
13 | } | 13 | } |
@@ -31,15 +31,19 @@ type ErrorCode struct { | @@ -31,15 +31,19 @@ type ErrorCode struct { | ||
31 | 31 | ||
32 | //ResponseMessage 统一返回消息结构体 | 32 | //ResponseMessage 统一返回消息结构体 |
33 | type ResponseMessage struct { | 33 | type ResponseMessage struct { |
34 | - ErrorCode | ||
35 | - Data interface{} `json:"data"` | 34 | + Errno int `json:"code"` |
35 | + Errmsg string `json:"msg"` | ||
36 | + Data interface{} `json:"data"` | ||
36 | } | 37 | } |
37 | 38 | ||
38 | func NewMesage(code string) *ResponseMessage { | 39 | func NewMesage(code string) *ResponseMessage { |
39 | - return &ResponseMessage{ | ||
40 | - ErrorCode: SearchErr(code), | ||
41 | - Data: nil, | 40 | + ecode := SearchErr(code) |
41 | + rsp := &ResponseMessage{ | ||
42 | + Errno: transformCode(ecode.Errno), | ||
43 | + Errmsg: ecode.Errmsg, | ||
44 | + Data: nil, | ||
42 | } | 45 | } |
46 | + return rsp | ||
43 | } | 47 | } |
44 | 48 | ||
45 | //ErrWithMessage 自定义错误结构 | 49 | //ErrWithMessage 自定义错误结构 |
@@ -79,10 +83,7 @@ func (e ErrWithMessage) Unwrap() error { | @@ -79,10 +83,7 @@ func (e ErrWithMessage) Unwrap() error { | ||
79 | 83 | ||
80 | //ParseToMessage 实现CustomErrParse的接口 | 84 | //ParseToMessage 实现CustomErrParse的接口 |
81 | func (e ErrWithMessage) ParseToMessage() *ResponseMessage { | 85 | func (e ErrWithMessage) ParseToMessage() *ResponseMessage { |
82 | - return &ResponseMessage{ | ||
83 | - ErrorCode: e.ErrorCode, | ||
84 | - Data: nil, | ||
85 | - } | 86 | + return NewMesage(e.Errno) |
86 | } | 87 | } |
87 | 88 | ||
88 | func SearchErr(code string) ErrorCode { | 89 | func SearchErr(code string) ErrorCode { |
@@ -92,13 +93,14 @@ func SearchErr(code string) ErrorCode { | @@ -92,13 +93,14 @@ func SearchErr(code string) ErrorCode { | ||
92 | func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) { | 93 | func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) { |
93 | // var msg *ResponseMessage | 94 | // var msg *ResponseMessage |
94 | if eRR == nil { | 95 | if eRR == nil { |
95 | - msg = NewMesage("00000") | 96 | + msg = NewMesage("0") |
96 | msg.Data = data | 97 | msg.Data = data |
97 | return msg | 98 | return msg |
98 | } | 99 | } |
99 | if x, ok := eRR.(CustomErrParse); ok { | 100 | if x, ok := eRR.(CustomErrParse); ok { |
100 | return x.ParseToMessage() | 101 | return x.ParseToMessage() |
101 | } | 102 | } |
103 | + | ||
102 | return NewMesage("1") | 104 | return NewMesage("1") |
103 | } | 105 | } |
104 | 106 |
@@ -2,12 +2,8 @@ package protocol | @@ -2,12 +2,8 @@ package protocol | ||
2 | 2 | ||
3 | var errmessge ErrorMap = map[string]string{ | 3 | var errmessge ErrorMap = map[string]string{ |
4 | //操作 | 4 | //操作 |
5 | - "00000": "成功", | ||
6 | - "1": "无效请求", | ||
7 | - "2": "添加成功", | ||
8 | - "3": "修改成功", | ||
9 | - "4": "删除成功", | ||
10 | - | 5 | + "0": "成功", |
6 | + "1": "无效请求", | ||
11 | //角色相关 | 7 | //角色相关 |
12 | "10001": "请先删除该分组下的其他角色", | 8 | "10001": "请先删除该分组下的其他角色", |
13 | "10002": "请先删除该角色下的人员", | 9 | "10002": "请先删除该角色下的人员", |
@@ -22,3 +18,16 @@ var errmessge ErrorMap = map[string]string{ | @@ -22,3 +18,16 @@ var errmessge ErrorMap = map[string]string{ | ||
22 | "10026": "登录凭证过期", | 18 | "10026": "登录凭证过期", |
23 | "10027": "无操作权限", | 19 | "10027": "无操作权限", |
24 | } | 20 | } |
21 | + | ||
22 | +//错误码转换 ,兼容需要 | ||
23 | +func transformCode(code string) int { | ||
24 | + switch code { | ||
25 | + case "0": | ||
26 | + return 0 //登录成功 | ||
27 | + case "10026": | ||
28 | + return 2 //token过期 | ||
29 | + case "10024": | ||
30 | + return 3 //token完全失效 | ||
31 | + } | ||
32 | + return -1 //请求成功,但业务检查不通过 | ||
33 | +} |
-
请 注册 或 登录 后发表评论