From 5a5f2c48e77c68f08796f97e20dc7d10f518a80d Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 3 Apr 2024 17:54:04 +0800 Subject: [PATCH] Adjust configuration settings --- config/redis.yml | 3 + pkg/common/config/config.go | 145 +++++++----------------------------- 2 files changed, 31 insertions(+), 117 deletions(-) diff --git a/config/redis.yml b/config/redis.yml index 8f774ce37..617c05358 100644 --- a/config/redis.yml +++ b/config/redis.yml @@ -2,3 +2,6 @@ redis: address: [ 172.28.0.1:16379 ] username: '' password: openIM123 + clusterMode: false + db: 0 + MaxRetry: 10 \ No newline at end of file diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index fa7de5c76..973a20562 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -15,11 +15,8 @@ package config import ( - "bytes" "github.com/openimsdk/tools/db/mongoutil" "github.com/openimsdk/tools/db/redisutil" - "github.com/openimsdk/tools/discovery" - "github.com/openimsdk/tools/system/program" "time" ) @@ -628,79 +625,34 @@ type User struct { } type Redis struct { - Address []string `mapstructure:"address"` - Username string `mapstructure:"username"` - Password string `mapstructure:"password"` + Address []string `mapstructure:"address"` + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` + ClusterMode bool `mapstructure:"clusterMode"` + DB int `mapstructure:"db"` + MaxRetry int `mapstructure:"MaxRetry"` +} + +type Hook struct { + Enable bool `mapstructure:"enable"` + Timeout int `mapstructure:"timeout"` + FailedContinue bool `mapstructure:"failedContinue"` } type Webhooks struct { - URL string `mapstructure:"url"` - BeforeSendSingleMsg struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"beforeSendSingleMsg"` - BeforeUpdateUserInfoEx struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"beforeUpdateUserInfoEx"` - AfterUpdateUserInfoEx struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"afterUpdateUserInfoEx"` - AfterSendSingleMsg struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"afterSendSingleMsg"` - BeforeSendGroupMsg struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"beforeSendGroupMsg"` - AfterSendGroupMsg struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"afterSendGroupMsg"` - MsgModify struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"msgModify"` - UserOnline struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"userOnline"` - UserOffline struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"userOffline"` - UserKickOff struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"userKickOff"` - OfflinePush struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"offlinePush"` - OnlinePush struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"onlinePush"` - SuperGroupOnlinePush struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` - FailedContinue bool `mapstructure:"failedContinue"` - } `mapstructure:"superGroupOnlinePush"` - // Add additional fields here following the same pattern for other hooks + URL string `mapstructure:"url"` + BeforeSendSingleMsg Hook `mapstructure:"beforeSendSingleMsg"` + BeforeUpdateUserInfoEx Hook `mapstructure:"beforeUpdateUserInfoEx"` + AfterUpdateUserInfoEx Hook `mapstructure:"afterUpdateUserInfoEx"` + AfterSendSingleMsg Hook `mapstructure:"afterSendSingleMsg"` + BeforeSendGroupMsg Hook `mapstructure:"beforeSendGroupMsg"` + AfterSendGroupMsg Hook `mapstructure:"afterSendGroupMsg"` + MsgModify Hook `mapstructure:"msgModify"` + UserOnline Hook `mapstructure:"userOnline"` + UserOffline Hook `mapstructure:"userOffline"` + UserKickOff Hook `mapstructure:"userKickOff"` + OfflinePush Hook `mapstructure:"offlinePush"` + OnlinePush Hook `mapstructure:"onlinePush"` } type ZooKeeper struct { @@ -744,55 +696,14 @@ func (r *Redis) Build() *redisutil.Config { } } -func (l LocalCache) Failed() time.Duration { +func (l *CacheConfig) Failed() time.Duration { return time.Second * time.Duration(l.FailedExpire) } -func (l LocalCache) Success() time.Duration { +func (l *CacheConfig) Success() time.Duration { return time.Second * time.Duration(l.SuccessExpire) } -func (l LocalCache) Enable() bool { +func (l *CacheConfig) Enable() bool { return l.Topic != "" && l.SlotNum > 0 && l.SlotSize > 0 } - -type localCache struct { - User LocalCache `yaml:"user"` - Group LocalCache `yaml:"group"` - Friend LocalCache `yaml:"friend"` - Conversation LocalCache `yaml:"conversation"` -} - -func (c *GlobalConfig) GetServiceNames() []string { - return []string{ - c.RpcRegisterName.OpenImUserName, - c.RpcRegisterName.OpenImFriendName, - c.RpcRegisterName.OpenImMsgName, - c.RpcRegisterName.OpenImPushName, - c.RpcRegisterName.OpenImMessageGatewayName, - c.RpcRegisterName.OpenImGroupName, - c.RpcRegisterName.OpenImAuthName, - c.RpcRegisterName.OpenImConversationName, - c.RpcRegisterName.OpenImThirdName, - } -} - -func (c *GlobalConfig) RegisterConf2Registry(registry discovery.SvcDiscoveryRegistry) error { - data, err := yaml.Marshal(c) - if err != nil { - return err - } - return registry.RegisterConf2Registry(ConfKey, data) -} - -func (c *GlobalConfig) GetConfFromRegistry(registry discovery.SvcDiscoveryRegistry) ([]byte, error) { - return registry.GetConfFromRegistry(ConfKey) -} - -func (c *GlobalConfig) EncodeConfig() []byte { - buf := bytes.NewBuffer(nil) - if err := yaml.NewEncoder(buf).Encode(c); err != nil { - program.ExitWithError(err) - } - return buf.Bytes() -}