mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 01:55:58 +08:00
groupCallback
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package call_back_struct
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type CommonCallbackReq struct {
|
||||
SendID string `json:"sendID"`
|
||||
CallbackCommand string `json:"callbackCommand"`
|
||||
@@ -20,6 +25,10 @@ type CommonCallbackReq struct {
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackResp interface {
|
||||
Parse() (IsPass bool, err error)
|
||||
}
|
||||
|
||||
type CommonCallbackResp struct {
|
||||
ActionCode int `json:"actionCode"`
|
||||
ErrCode int `json:"errCode"`
|
||||
@@ -27,6 +36,18 @@ type CommonCallbackResp struct {
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
func (c *CommonCallbackResp) Parse() (isPass bool, err error) {
|
||||
if c.ActionCode != 0 {
|
||||
err = errors.New(fmt.Sprintf("callback response error actionCode is %d, errCode is %d, errMsg is %s", c.ActionCode, c.ErrCode, c.ErrMsg))
|
||||
return false, err
|
||||
}
|
||||
if c.ErrCode != 0 {
|
||||
err = errors.New(fmt.Sprintf("callback response error actionCode is %d, errCode is %d, errMsg is %s", c.ActionCode, c.ErrCode, c.ErrMsg))
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
type UserStatusBaseCallback struct {
|
||||
CallbackCommand string `json:"callbackCommand"`
|
||||
OperationID string `json:"operationID"`
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
cbApi "Open_IM/pkg/call_back_struct"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
@@ -56,16 +57,22 @@ func Post(url string, data interface{}, timeOutSecond int) (content []byte, err
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func CallBackPostReturn(url, callbackCommand string, input, output interface{}, timeOut int) error {
|
||||
func CallBackPostReturn(url, callbackCommand string, input interface{}, output cbApi.CallbackResp, timeOut int, failedContinue *bool) (bool, error) {
|
||||
v := urlLib.Values{}
|
||||
v.Set("callbackCommand", callbackCommand)
|
||||
url = url + "?" + v.Encode()
|
||||
b, err := Post(url, input, timeOut)
|
||||
if err != nil {
|
||||
return err
|
||||
if failedContinue != nil {
|
||||
return *failedContinue, err
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
if err = json.Unmarshal(b, output); err != nil {
|
||||
return err
|
||||
if failedContinue != nil {
|
||||
return *failedContinue, err
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
return nil
|
||||
return output.Parse()
|
||||
}
|
||||
|
||||
@@ -81,9 +81,9 @@ func SetContextInfo(ctx context.Context, funcName string, err error, args ...int
|
||||
funcInfo.Err = err
|
||||
*t.Funcs = append(*t.Funcs, funcInfo)
|
||||
if err != nil {
|
||||
log.NewError(t.OperationID, funcName, "error: ", err, funcInfo.Args)
|
||||
log.NewError(t.OperationID, funcName, "error", err, "args", funcInfo.Args)
|
||||
} else {
|
||||
log.NewInfo(t.OperationID, funcName, "args: ", funcInfo.Args)
|
||||
log.NewInfo(t.OperationID, funcName, "args", funcInfo.Args)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user