test-errcode
wangchuxiao 2 years ago
parent 51529eece3
commit 40438f529a

@ -40,7 +40,7 @@ func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb.
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOfflinePushCommand, req, resp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
if !config.Config.Callback.CallbackOfflinePush.CallbackFailedContinue {
if !*config.Config.Callback.CallbackOfflinePush.CallbackFailedContinue {
callbackResp.ActionCode = constant.ActionForbidden
return callbackResp
} else {

@ -35,7 +35,7 @@ func callbackBeforeCreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq)
//utils.CopyStructFields(req, msg.MsgData)
defer log.NewDebug(req.OperationID, utils.GetSelfFuncName(), commonCallbackReq, *resp)
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeCreateGroupCommand, commonCallbackReq,
resp, config.Config.Callback.CallbackBeforeCreateGroup.CallbackTimeOut, &config.Config.Callback.CallbackBeforeCreateGroup.CallbackFailedContinue)
resp, config.Config.Callback.CallbackBeforeCreateGroup)
if err == nil {
if resp.GroupID != nil {
req.GroupInfo.GroupID = *resp.GroupID
@ -98,7 +98,7 @@ func CallbackBeforeMemberJoinGroup(ctx context.Context, operationID string, grou
CommonCallbackResp: &callbackResp,
}
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeMemberJoinGroupCommand, callbackReq,
resp, config.Config.Callback.CallbackBeforeMemberJoinGroup.CallbackTimeOut, &config.Config.Callback.CallbackBeforeMemberJoinGroup.CallbackFailedContinue)
resp, config.Config.Callback.CallbackBeforeMemberJoinGroup)
if err == nil {
if resp.MuteEndTime != nil {
groupMember.MuteEndTime = utils.UnixSecondToTime(*resp.MuteEndTime)

@ -20,10 +20,10 @@ const ConfName = "openIMConf"
var Config config
type callBackConfig struct {
Enable bool `yaml:"enable"`
CallbackTimeOut int `yaml:"callbackTimeOut"`
CallbackFailedContinue bool `yaml:"callbackFailedContinue"`
type CallBackConfig struct {
Enable bool `yaml:"enable"`
CallbackTimeOut int `yaml:"callbackTimeOut"`
CallbackFailedContinue *bool `yaml:"callbackFailedContinue"`
}
type config struct {
@ -283,21 +283,21 @@ type config struct {
Callback struct {
CallbackUrl string `yaml:"callbackUrl"`
CallbackBeforeSendSingleMsg callBackConfig `yaml:"callbackBeforeSendSingleMsg"`
CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackAfterSendSingleMsg"`
CallbackBeforeSendGroupMsg callBackConfig `yaml:"callbackBeforeSendGroupMsg"`
CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"`
CallbackMsgModify callBackConfig `yaml:"callbackMsgModify"`
CallbackUserOnline callBackConfig `yaml:"callbackUserOnline"`
CallbackUserOffline callBackConfig `yaml:"callbackUserOffline"`
CallbackUserKickOff callBackConfig `yaml:"callbackUserKickOff"`
CallbackOfflinePush callBackConfig `yaml:"callbackOfflinePush"`
CallbackOnlinePush callBackConfig `yaml:"callbackOnlinePush"`
CallbackBeforeSuperGroupOnlinePush callBackConfig `yaml:"callbackSuperGroupOnlinePush"`
CallbackBeforeAddFriend callBackConfig `yaml:"callbackBeforeAddFriend"`
CallbackBeforeCreateGroup callBackConfig `yaml:"callbackBeforeCreateGroup"`
CallbackBeforeMemberJoinGroup callBackConfig `yaml:"callbackBeforeMemberJoinGroup"`
CallbackBeforeSetGroupMemberInfo callBackConfig `yaml:"callbackBeforeSetGroupMemberInfo"`
CallbackBeforeSendSingleMsg CallBackConfig `yaml:"callbackBeforeSendSingleMsg"`
CallbackAfterSendSingleMsg CallBackConfig `yaml:"callbackAfterSendSingleMsg"`
CallbackBeforeSendGroupMsg CallBackConfig `yaml:"callbackBeforeSendGroupMsg"`
CallbackAfterSendGroupMsg CallBackConfig `yaml:"callbackAfterSendGroupMsg"`
CallbackMsgModify CallBackConfig `yaml:"callbackMsgModify"`
CallbackUserOnline CallBackConfig `yaml:"callbackUserOnline"`
CallbackUserOffline CallBackConfig `yaml:"callbackUserOffline"`
CallbackUserKickOff CallBackConfig `yaml:"callbackUserKickOff"`
CallbackOfflinePush CallBackConfig `yaml:"callbackOfflinePush"`
CallbackOnlinePush CallBackConfig `yaml:"callbackOnlinePush"`
CallbackBeforeSuperGroupOnlinePush CallBackConfig `yaml:"callbackSuperGroupOnlinePush"`
CallbackBeforeAddFriend CallBackConfig `yaml:"callbackBeforeAddFriend"`
CallbackBeforeCreateGroup CallBackConfig `yaml:"callbackBeforeCreateGroup"`
CallbackBeforeMemberJoinGroup CallBackConfig `yaml:"callbackBeforeMemberJoinGroup"`
CallbackBeforeSetGroupMemberInfo CallBackConfig `yaml:"callbackBeforeSetGroupMemberInfo"`
} `yaml:"callback"`
Notification struct {
///////////////////////group/////////////////////////////
@ -640,8 +640,8 @@ func unmarshalConfig(config interface{}, configPath string) {
}
func initConfig(config interface{}, configName, configPath string) {
var env string
if configPath == "" {
var env string
if configName == "config.yaml" {
env = "CONFIG_NAME"
} else if configName == "usualConfig.yaml" {
@ -649,32 +649,17 @@ func initConfig(config interface{}, configName, configPath string) {
}
cfgName := os.Getenv(env)
if len(cfgName) != 0 {
bytes, err := ioutil.ReadFile(filepath.Join(cfgName, "config", configName))
if err != nil {
bytes, err = ioutil.ReadFile(filepath.Join(Root, "config", configName))
if err != nil {
panic(err.Error() + " config: " + filepath.Join(cfgName, "config", configName))
}
configPath = filepath.Join(cfgName, "config", configName)
_, err := os.Stat(configPath)
if os.IsNotExist(err) {
configPath = filepath.Join(Root, "config", configName)
} else {
Root = cfgName
}
if err = yaml.Unmarshal(bytes, config); err != nil {
panic(err.Error())
}
return
} else {
bytes, err := ioutil.ReadFile(fmt.Sprintf("../config/%s", configName))
if err != nil {
panic(err.Error() + configName)
}
if err = yaml.Unmarshal(bytes, config); err != nil {
panic(err.Error())
}
configPath = fmt.Sprintf("../config/%s", configName)
}
} else {
}
unmarshalConfig(config, configPath)
}
@ -745,11 +730,9 @@ func InitConfig(configPath string) {
if Config.Push.Getui.Enable == nil {
Config.Push.Getui.Enable = &UsualConfig.Push.Getui.Enable
}
if Config.Secret == "" {
Config.Secret = UsualConfig.Secret
}
if Config.TokenPolicy.AccessExpire == 0 {
Config.TokenPolicy.AccessExpire = UsualConfig.Tokenpolicy.AccessExpire
}
@ -759,81 +742,5 @@ func InitConfig(configPath string) {
}
func init() {
initConfig(&Config, "config.yaml", "")
initConfig(&UsualConfig, "usualConfig.yaml", "")
if Config.Etcd.UserName == "" {
Config.Etcd.UserName = UsualConfig.Etcd.UserName
}
if Config.Etcd.Password == "" {
Config.Etcd.Password = UsualConfig.Etcd.Password
}
if Config.Etcd.Secret == "" {
Config.Etcd.Secret = UsualConfig.Etcd.Secret
}
if Config.Mysql.DBUserName == "" {
Config.Mysql.DBUserName = UsualConfig.Mysql.DBUserName
}
if Config.Mysql.DBPassword == "" {
Config.Mysql.DBPassword = UsualConfig.Mysql.DBPassword
}
if Config.Redis.DBUserName == "" {
Config.Redis.DBUserName = UsualConfig.Redis.DBUserName
}
if Config.Redis.DBPassWord == "" {
Config.Redis.DBPassWord = UsualConfig.Redis.DBPassword
}
if Config.Mongo.DBUserName == "" {
Config.Mongo.DBUserName = UsualConfig.Mongo.DBUserName
}
if Config.Mongo.DBPassword == "" {
Config.Mongo.DBPassword = UsualConfig.Mongo.DBPassword
}
if Config.Kafka.SASLUserName == "" {
Config.Kafka.SASLUserName = UsualConfig.Kafka.SASLUserName
}
if Config.Kafka.SASLPassword == "" {
Config.Kafka.SASLPassword = UsualConfig.Kafka.SASLPassword
}
if Config.Credential.Minio.AccessKeyID == "" {
Config.Credential.Minio.AccessKeyID = UsualConfig.Credential.Minio.AccessKeyID
}
if Config.Credential.Minio.SecretAccessKey == "" {
Config.Credential.Minio.SecretAccessKey = UsualConfig.Credential.Minio.SecretAccessKey
}
if Config.Credential.Minio.Endpoint == "" {
Config.Credential.Minio.Endpoint = UsualConfig.Credential.Minio.Endpoint
}
if Config.MessageVerify.FriendVerify == nil {
Config.MessageVerify.FriendVerify = &UsualConfig.Messageverify.FriendVerify
}
if Config.Push.Getui.MasterSecret == "" {
Config.Push.Getui.MasterSecret = UsualConfig.Push.Getui.MasterSecret
}
if Config.Push.Getui.AppKey == "" {
Config.Push.Getui.AppKey = UsualConfig.Push.Getui.AppKey
}
if Config.Push.Getui.PushUrl == "" {
Config.Push.Getui.PushUrl = UsualConfig.Push.Getui.PushUrl
}
if Config.Push.Getui.Enable == nil {
Config.Push.Getui.Enable = &UsualConfig.Push.Getui.Enable
}
if Config.Secret == "" {
Config.Secret = UsualConfig.Secret
}
if Config.TokenPolicy.AccessExpire == 0 {
Config.TokenPolicy.AccessExpire = UsualConfig.Tokenpolicy.AccessExpire
}
if Config.TokenPolicy.AccessSecret == "" {
Config.TokenPolicy.AccessSecret = UsualConfig.Tokenpolicy.AccessSecret
}
InitConfig("")
}

@ -8,6 +8,7 @@ package http
import (
cbApi "Open_IM/pkg/callback_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"bytes"
"encoding/json"
@ -58,19 +59,19 @@ func Post(url string, data interface{}, timeOutSecond int) (content []byte, err
return result, nil
}
func CallBackPostReturn(url, callbackCommand string, input interface{}, output cbApi.CallbackResp, timeOut int, failedContinue *bool) error {
func CallBackPostReturn(url, callbackCommand string, input interface{}, output cbApi.CallbackResp, callbackConfig config.CallBackConfig) error {
v := urlLib.Values{}
v.Set("callbackCommand", callbackCommand)
url = url + "?" + v.Encode()
b, err := Post(url, input, timeOut)
b, err := Post(url, input, callbackConfig.CallbackTimeOut)
if err != nil {
if failedContinue != nil && *failedContinue {
if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue {
return constant.ErrCallbackContinue
}
return constant.NewErrNetwork(err)
}
if err = json.Unmarshal(b, output); err != nil {
if failedContinue != nil && *failedContinue {
if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue {
return constant.ErrCallbackContinue
}
return constant.NewErrData(err)

Loading…
Cancel
Save