package entity import "encoding/json" var DefaultSuccessHttpResult = &HttpResult{Status: true, Code: "1000", Message: "请求成功。"} var DefaultFailHttpResult = &HttpResult{Status: true, Code: "2000", Message: "请求失败。"} type HttpResult struct { Status bool `json:"status"` Code string `json:"code"` Message string `json:"message"` Details string `json:"details"` } type Response struct { Code int `json:"code"` // 错误码 Msg string `json:"msg"` // 错误描述 Data interface{} `json:"data"` // 返回数据 Total interface{} `json:"total"` // 分页的total数量 } // 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) }