diff --git a/mvc/controller.go b/mvc/controller.go index 7cc7a58..58634d5 100644 --- a/mvc/controller.go +++ b/mvc/controller.go @@ -2,6 +2,7 @@ package mvc import ( "github.com/astaxie/beego" + "golib.gaore.com/GaoreGo/beegoinit/response" "strings" ) @@ -24,7 +25,12 @@ func (this *BaseController) Prepare() { } func (this *BaseController) RespJson(status bool, code int, msg string, data interface{}) { - this.Data["json"] = &map[string]interface{}{"status": status, "code": code, "msg": msg, "data": data} + this.Data["json"] = &response.Json{ + Code: code, + Data: data, + Msg: msg, + Status: status, + } this.ServeJSON() } diff --git a/response/json.go b/response/json.go new file mode 100644 index 0000000..8df495e --- /dev/null +++ b/response/json.go @@ -0,0 +1,17 @@ +package response + +type Json struct { + Code int `json:"code"` + Data interface{} `json:"data"` + Msg string `json:"msg"` + Status bool `json:"status"` +} + +func GetDefaultJsonResponse() *Json { + return &Json{ + Code: 0, + Data: nil, + Msg: "ok", + Status: true, + } +}