|
@@ -1,5 +1,7 @@
|
|
package entity
|
|
package entity
|
|
|
|
|
|
|
|
+import "encoding/json"
|
|
|
|
+
|
|
var DefaultSuccessHttpResult = &HttpResult{Status: true, Code: "1000", Message: "请求成功。"}
|
|
var DefaultSuccessHttpResult = &HttpResult{Status: true, Code: "1000", Message: "请求成功。"}
|
|
var DefaultFailHttpResult = &HttpResult{Status: true, Code: "2000", Message: "请求失败。"}
|
|
var DefaultFailHttpResult = &HttpResult{Status: true, Code: "2000", Message: "请求失败。"}
|
|
|
|
|
|
@@ -9,3 +11,24 @@ type HttpResult struct {
|
|
Message string `json:"message"`
|
|
Message string `json:"message"`
|
|
Details string `json:"details"`
|
|
Details string `json:"details"`
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+type Response struct {
|
|
|
|
+ Code int `json:"code"` // 错误码
|
|
|
|
+ Msg string `json:"msg"` // 错误描述
|
|
|
|
+ Data interface{} `json:"data"` // 返回数据
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// ToString 返回 JSON 格式的错误详情
|
|
|
|
+func (res *Response) ToString() string {
|
|
|
|
+ err := &struct {
|
|
|
|
+ Code int `json:"code"`
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
+ Data interface{} `json:"data"`
|
|
|
|
+ }{
|
|
|
|
+ Code: res.Code,
|
|
|
|
+ Msg: res.Msg,
|
|
|
|
+ Data: res.Data,
|
|
|
|
+ }
|
|
|
|
+ raw, _ := json.Marshal(err)
|
|
|
|
+ return string(raw)
|
|
|
|
+}
|