diff --git a/go.mod b/go.mod index 9d805b8..caa0bf6 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/astaxie/beego v1.12.2 github.com/go-check/check v0.0.0-20200227125254-8fa46927fb4f // indirect github.com/go-sql-driver/mysql v1.5.0 - github.com/lib/pq v1.0.0 golib.gaore.com/GaoreGo/cast v1.3.2 golib.gaore.com/GaoreGo/goes v1.2.2 // indirect golib.gaore.com/GaoreGo/grconfig v1.1.0 diff --git a/mvc/controller.go b/mvc/controller.go index 58634d5..775226d 100644 --- a/mvc/controller.go +++ b/mvc/controller.go @@ -2,7 +2,7 @@ package mvc import ( "github.com/astaxie/beego" - "golib.gaore.com/GaoreGo/beegoinit/response" + "golib.gaore.com/GaoreGo/beegoinit/response/json" "strings" ) @@ -25,7 +25,7 @@ func (this *BaseController) Prepare() { } func (this *BaseController) RespJson(status bool, code int, msg string, data interface{}) { - this.Data["json"] = &response.Json{ + this.Data["json"] = &json.Json{ Code: code, Data: data, Msg: msg, diff --git a/response/json.go b/response/json.go deleted file mode 100644 index 8df495e..0000000 --- a/response/json.go +++ /dev/null @@ -1,17 +0,0 @@ -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, - } -} diff --git a/response/json/json.go b/response/json/json.go new file mode 100644 index 0000000..65d6faa --- /dev/null +++ b/response/json/json.go @@ -0,0 +1,44 @@ +package json + +type Json struct { + Code int `json:"code"` + Data interface{} `json:"data"` + Msg string `json:"msg"` + Status bool `json:"status"` +} + +func GetDefaultJsonSuccessResponse() *Json { + return &Json{ + Code: 0, + Data: nil, + Msg: "ok", + Status: true, + } +} + +func GetDefaultJsonFailedResponse() *Json { + return &Json{ + Code: 1, + Data: nil, + Msg: "unknow", + Status: false, + } +} + +func New(status bool, code int, msg string, data ...interface{}) *Json { + if len(data) > 0 { + return &Json{ + Code: code, + Data: data[0], + Msg: msg, + Status: status, + } + } else { + return &Json{ + Code: code, + Data: nil, + Msg: msg, + Status: status, + } + } +}