mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-10 20:15:59 +08:00
msg cb
This commit is contained in:
@@ -25,26 +25,36 @@ type CommonCallbackReq struct {
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
func (c *CommonCallbackReq) GetCallbackCommand() string {
|
||||
return c.CallbackCommand
|
||||
}
|
||||
|
||||
type CallbackReq interface {
|
||||
GetCallbackCommand() string
|
||||
}
|
||||
|
||||
type CallbackResp interface {
|
||||
Parse() (err error)
|
||||
}
|
||||
|
||||
type CommonCallbackResp struct {
|
||||
ActionCode int `json:"actionCode"`
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
OperationID string `json:"operationID"`
|
||||
ActionCode int `json:"actionCode"`
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
//OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
func (c *CommonCallbackResp) Parse() (err error) {
|
||||
func (c *CommonCallbackResp) Parse() error {
|
||||
if c == nil {
|
||||
return constant.ErrData.Wrap("callback common is nil")
|
||||
}
|
||||
if c.ActionCode != constant.NoError || c.ErrCode != constant.NoError {
|
||||
newErr := constant.ErrCallback
|
||||
newErr.ErrCode = c.ErrCode
|
||||
newErr.DetailErrMsg = fmt.Sprintf("callback response error actionCode is %d, errCode is %d, errMsg is %s", c.ActionCode, c.ErrCode, c.ErrMsg)
|
||||
err = newErr
|
||||
return
|
||||
return newErr.Wrap()
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
type UserStatusBaseCallback struct {
|
||||
|
||||
@@ -78,3 +78,23 @@ func CallBackPostReturn(url, callbackCommand string, input interface{}, output c
|
||||
}
|
||||
return output.Parse()
|
||||
}
|
||||
|
||||
func CallBackPostReturnV2(url string, req cbapi.CallbackReq, resp cbapi.CallbackResp, callbackConfig config.CallBackConfig) error {
|
||||
v := urlLib.Values{}
|
||||
v.Set("callbackCommand", req.GetCallbackCommand())
|
||||
url = url + "?" + v.Encode()
|
||||
b, err := Post(url, req, callbackConfig.CallbackTimeOut)
|
||||
if err != nil {
|
||||
if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue {
|
||||
return constant.ErrCallbackContinue
|
||||
}
|
||||
return constant.NewErrNetwork(err)
|
||||
}
|
||||
if err = json.Unmarshal(b, resp); err != nil {
|
||||
if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue {
|
||||
return constant.ErrCallbackContinue
|
||||
}
|
||||
return constant.NewErrData(err)
|
||||
}
|
||||
return resp.Parse()
|
||||
}
|
||||
|
||||
@@ -425,3 +425,11 @@ func Unwrap(err error) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// NotNilReplace 当new_不为空时, 将old设置为new_
|
||||
func NotNilReplace[T any](old, new_ *T) {
|
||||
if old == nil || new_ == nil {
|
||||
return
|
||||
}
|
||||
*old = *new_
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user