修复SetStatus的bug

This commit is contained in:
eson
2023-06-21 14:26:29 +08:00
parent 152e18b0e5
commit 2c0cd12a15
12 changed files with 29 additions and 86 deletions

View File

@@ -22,7 +22,9 @@ var (
CodeOrderNotFoundErr = &StatusResponse{5030, "the order not found"} //未找到订单
CodeOrderNotCancelledErr = &StatusResponse{5031, "The current order cannot be cancelled"} // 当前订单无法取消
CodePayNotFoundErr = &StatusResponse{5020, "The pay not found"} // 支付信息无法查询
CodePayNotFoundErr = &StatusResponse{5020, "The pay not found"} // 支付信息无法查询
CodePayCancelOk = &StatusResponse{5021, "Cancel successfully"} // 支付取消
CodePayCancelNotOk = &StatusResponse{5022, "Cancel failure"} // 支付取消
CodeGuestDupErr = &StatusResponse{5010, "the user is already a guest user and does not need to apply again"} // 用户已经是访客用户,不需要重复申请
CodeGuestGenErr = &StatusResponse{5011, "serialization failed for guest_id of the visitor"} // 访客ID序列化失败
@@ -96,11 +98,16 @@ func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, data
Code: sr.Code,
Message: msg,
}
if len(data) == 1 {
switch len(data) {
case 0:
// 0 直接返回
case 1:
newResp.Data = data[0]
} else {
default:
panic("data只接收一个 data")
}
return newResp
}
@@ -109,10 +116,13 @@ func (resp *Response) SetStatusAddMessage(sr *StatusResponse, msg string, data .
Code: sr.Code,
Message: sr.Message + ":" + msg,
}
if len(data) == 1 {
switch len(data) {
case 0:
// 0 直接返回
case 1:
newResp.Data = data[0]
} else {
panic("data只接收一个")
default:
panic("data只接收一个 data")
}
return newResp
}