作者 tangxvhui

返回code 修改

... ... @@ -28,7 +28,7 @@ func (controller BaseController) ResponseError(err error) {
if e, ok := err.(lib.ServiceError); ok {
if !(e.Code == lib.ARG_ERROR || e.Code == lib.BUSINESS_ERROR) {
controller.Data["json"] = protocol.ResponseData{
Code: "-1",
Code: -1,
Msg: "服务异常",
Data: struct{}{},
}
... ... @@ -38,7 +38,7 @@ func (controller BaseController) ResponseError(err error) {
}
}
controller.Data["json"] = protocol.ResponseData{
Code: "-1",
Code: -1,
Msg: err.Error(),
Data: struct{}{},
}
... ... @@ -52,7 +52,7 @@ func (controller BaseController) ResponseData(data interface{}) {
data = struct{}{}
}
controller.Data["json"] = protocol.ResponseData{
Code: "0",
Code: 0,
Msg: "ok",
Data: data,
}
... ... @@ -64,7 +64,7 @@ func (controller BaseController) ResponsePageList(data interface{}, totalRow int
data = []interface{}{}
}
controller.Data["json"] = protocol.ResponseData{
Code: "0",
Code: 0,
Msg: "ok",
Data: map[string]map[string]interface{}{
"gridResult": map[string]interface{}{
... ... @@ -90,10 +90,6 @@ func (controller *BaseController) Finish() {
////Prepare 重写 beego.Controller 的Prepare方法
func (controller *BaseController) Prepare() {
//跨域处理
// controller.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
// controller.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
logs.Info("====>Recv Request:", controller.Ctx.Input.URI())
if controller.Ctx.Input.IsPost() || controller.Ctx.Input.IsPut() {
bodyByte := controller.Ctx.Input.RequestBody
... ... @@ -128,14 +124,14 @@ func (controller *BaseController) ValidJWTToken() bool {
if mytoken.IsJwtErrorExpired(err) {
//token超时
controller.Data["json"] = protocol.ResponseData{
Code: "2",
Code: 2,
Msg: "token过期,请重新登录",
Data: struct{}{},
}
controller.ServeJSON()
} else {
controller.Data["json"] = protocol.ResponseData{
Code: "-1",
Code: -1,
Msg: "token校验失败",
Data: struct{}{},
}
... ...
package protocol
type ResponseData struct {
Code string `json:"code"`
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
... ...