...
|
...
|
@@ -31,15 +31,19 @@ type ErrorCode struct { |
|
|
|
|
|
//ResponseMessage 统一返回消息结构体
|
|
|
type ResponseMessage struct {
|
|
|
ErrorCode
|
|
|
Data interface{} `json:"data"`
|
|
|
Errno int `json:"code"`
|
|
|
Errmsg string `json:"msg"`
|
|
|
Data interface{} `json:"data"`
|
|
|
}
|
|
|
|
|
|
func NewMesage(code string) *ResponseMessage {
|
|
|
return &ResponseMessage{
|
|
|
ErrorCode: SearchErr(code),
|
|
|
Data: nil,
|
|
|
ecode := SearchErr(code)
|
|
|
rsp := &ResponseMessage{
|
|
|
Errno: transformCode(ecode.Errno),
|
|
|
Errmsg: ecode.Errmsg,
|
|
|
Data: nil,
|
|
|
}
|
|
|
return rsp
|
|
|
}
|
|
|
|
|
|
//ErrWithMessage 自定义错误结构
|
...
|
...
|
@@ -79,10 +83,7 @@ func (e ErrWithMessage) Unwrap() error { |
|
|
|
|
|
//ParseToMessage 实现CustomErrParse的接口
|
|
|
func (e ErrWithMessage) ParseToMessage() *ResponseMessage {
|
|
|
return &ResponseMessage{
|
|
|
ErrorCode: e.ErrorCode,
|
|
|
Data: nil,
|
|
|
}
|
|
|
return NewMesage(e.Errno)
|
|
|
}
|
|
|
|
|
|
func SearchErr(code string) ErrorCode {
|
...
|
...
|
@@ -92,13 +93,14 @@ func SearchErr(code string) ErrorCode { |
|
|
func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) {
|
|
|
// var msg *ResponseMessage
|
|
|
if eRR == nil {
|
|
|
msg = NewMesage("00000")
|
|
|
msg = NewMesage("0")
|
|
|
msg.Data = data
|
|
|
return msg
|
|
|
}
|
|
|
if x, ok := eRR.(CustomErrParse); ok {
|
|
|
return x.ParseToMessage()
|
|
|
}
|
|
|
|
|
|
return NewMesage("1")
|
|
|
}
|
|
|
|
...
|
...
|
|