作者 tangxvhui

返回code 修改

@@ -28,7 +28,7 @@ func (controller BaseController) ResponseError(err error) { @@ -28,7 +28,7 @@ func (controller BaseController) ResponseError(err error) {
28 if e, ok := err.(lib.ServiceError); ok { 28 if e, ok := err.(lib.ServiceError); ok {
29 if !(e.Code == lib.ARG_ERROR || e.Code == lib.BUSINESS_ERROR) { 29 if !(e.Code == lib.ARG_ERROR || e.Code == lib.BUSINESS_ERROR) {
30 controller.Data["json"] = protocol.ResponseData{ 30 controller.Data["json"] = protocol.ResponseData{
31 - Code: "-1", 31 + Code: -1,
32 Msg: "服务异常", 32 Msg: "服务异常",
33 Data: struct{}{}, 33 Data: struct{}{},
34 } 34 }
@@ -38,7 +38,7 @@ func (controller BaseController) ResponseError(err error) { @@ -38,7 +38,7 @@ func (controller BaseController) ResponseError(err error) {
38 } 38 }
39 } 39 }
40 controller.Data["json"] = protocol.ResponseData{ 40 controller.Data["json"] = protocol.ResponseData{
41 - Code: "-1", 41 + Code: -1,
42 Msg: err.Error(), 42 Msg: err.Error(),
43 Data: struct{}{}, 43 Data: struct{}{},
44 } 44 }
@@ -52,7 +52,7 @@ func (controller BaseController) ResponseData(data interface{}) { @@ -52,7 +52,7 @@ func (controller BaseController) ResponseData(data interface{}) {
52 data = struct{}{} 52 data = struct{}{}
53 } 53 }
54 controller.Data["json"] = protocol.ResponseData{ 54 controller.Data["json"] = protocol.ResponseData{
55 - Code: "0", 55 + Code: 0,
56 Msg: "ok", 56 Msg: "ok",
57 Data: data, 57 Data: data,
58 } 58 }
@@ -64,7 +64,7 @@ func (controller BaseController) ResponsePageList(data interface{}, totalRow int @@ -64,7 +64,7 @@ func (controller BaseController) ResponsePageList(data interface{}, totalRow int
64 data = []interface{}{} 64 data = []interface{}{}
65 } 65 }
66 controller.Data["json"] = protocol.ResponseData{ 66 controller.Data["json"] = protocol.ResponseData{
67 - Code: "0", 67 + Code: 0,
68 Msg: "ok", 68 Msg: "ok",
69 Data: map[string]map[string]interface{}{ 69 Data: map[string]map[string]interface{}{
70 "gridResult": map[string]interface{}{ 70 "gridResult": map[string]interface{}{
@@ -90,10 +90,6 @@ func (controller *BaseController) Finish() { @@ -90,10 +90,6 @@ func (controller *BaseController) Finish() {
90 90
91 ////Prepare 重写 beego.Controller 的Prepare方法 91 ////Prepare 重写 beego.Controller 的Prepare方法
92 func (controller *BaseController) Prepare() { 92 func (controller *BaseController) Prepare() {
93 - //跨域处理  
94 - // controller.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")  
95 - // controller.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")  
96 -  
97 logs.Info("====>Recv Request:", controller.Ctx.Input.URI()) 93 logs.Info("====>Recv Request:", controller.Ctx.Input.URI())
98 if controller.Ctx.Input.IsPost() || controller.Ctx.Input.IsPut() { 94 if controller.Ctx.Input.IsPost() || controller.Ctx.Input.IsPut() {
99 bodyByte := controller.Ctx.Input.RequestBody 95 bodyByte := controller.Ctx.Input.RequestBody
@@ -128,14 +124,14 @@ func (controller *BaseController) ValidJWTToken() bool { @@ -128,14 +124,14 @@ func (controller *BaseController) ValidJWTToken() bool {
128 if mytoken.IsJwtErrorExpired(err) { 124 if mytoken.IsJwtErrorExpired(err) {
129 //token超时 125 //token超时
130 controller.Data["json"] = protocol.ResponseData{ 126 controller.Data["json"] = protocol.ResponseData{
131 - Code: "2", 127 + Code: 2,
132 Msg: "token过期,请重新登录", 128 Msg: "token过期,请重新登录",
133 Data: struct{}{}, 129 Data: struct{}{},
134 } 130 }
135 controller.ServeJSON() 131 controller.ServeJSON()
136 } else { 132 } else {
137 controller.Data["json"] = protocol.ResponseData{ 133 controller.Data["json"] = protocol.ResponseData{
138 - Code: "-1", 134 + Code: -1,
139 Msg: "token校验失败", 135 Msg: "token校验失败",
140 Data: struct{}{}, 136 Data: struct{}{},
141 } 137 }
1 package protocol 1 package protocol
2 2
3 type ResponseData struct { 3 type ResponseData struct {
4 - Code string `json:"code"` 4 + Code int `json:"code"`
5 Msg string `json:"msg"` 5 Msg string `json:"msg"`
6 Data interface{} `json:"data"` 6 Data interface{} `json:"data"`
7 } 7 }