Adjust configuration settings

pull/2148/head
skiffer-git 2 years ago
parent 54630464bd
commit 5a5f2c48e7

@ -2,3 +2,6 @@ redis:
address: [ 172.28.0.1:16379 ] address: [ 172.28.0.1:16379 ]
username: '' username: ''
password: openIM123 password: openIM123
clusterMode: false
db: 0
MaxRetry: 10

@ -15,11 +15,8 @@
package config package config
import ( import (
"bytes"
"github.com/openimsdk/tools/db/mongoutil" "github.com/openimsdk/tools/db/mongoutil"
"github.com/openimsdk/tools/db/redisutil" "github.com/openimsdk/tools/db/redisutil"
"github.com/openimsdk/tools/discovery"
"github.com/openimsdk/tools/system/program"
"time" "time"
) )
@ -631,76 +628,31 @@ type Redis struct {
Address []string `mapstructure:"address"` Address []string `mapstructure:"address"`
Username string `mapstructure:"username"` Username string `mapstructure:"username"`
Password string `mapstructure:"password"` Password string `mapstructure:"password"`
ClusterMode bool `mapstructure:"clusterMode"`
DB int `mapstructure:"db"`
MaxRetry int `mapstructure:"MaxRetry"`
} }
type Webhooks struct { type Hook 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"` Enable bool `mapstructure:"enable"`
Timeout int `mapstructure:"timeout"` Timeout int `mapstructure:"timeout"`
FailedContinue bool `mapstructure:"failedContinue"` FailedContinue bool `mapstructure:"failedContinue"`
} `mapstructure:"userKickOff"` }
OfflinePush struct {
Enable bool `mapstructure:"enable"` type Webhooks struct {
Timeout int `mapstructure:"timeout"` URL string `mapstructure:"url"`
FailedContinue bool `mapstructure:"failedContinue"` BeforeSendSingleMsg Hook `mapstructure:"beforeSendSingleMsg"`
} `mapstructure:"offlinePush"` BeforeUpdateUserInfoEx Hook `mapstructure:"beforeUpdateUserInfoEx"`
OnlinePush struct { AfterUpdateUserInfoEx Hook `mapstructure:"afterUpdateUserInfoEx"`
Enable bool `mapstructure:"enable"` AfterSendSingleMsg Hook `mapstructure:"afterSendSingleMsg"`
Timeout int `mapstructure:"timeout"` BeforeSendGroupMsg Hook `mapstructure:"beforeSendGroupMsg"`
FailedContinue bool `mapstructure:"failedContinue"` AfterSendGroupMsg Hook `mapstructure:"afterSendGroupMsg"`
} `mapstructure:"onlinePush"` MsgModify Hook `mapstructure:"msgModify"`
SuperGroupOnlinePush struct { UserOnline Hook `mapstructure:"userOnline"`
Enable bool `mapstructure:"enable"` UserOffline Hook `mapstructure:"userOffline"`
Timeout int `mapstructure:"timeout"` UserKickOff Hook `mapstructure:"userKickOff"`
FailedContinue bool `mapstructure:"failedContinue"` OfflinePush Hook `mapstructure:"offlinePush"`
} `mapstructure:"superGroupOnlinePush"` OnlinePush Hook `mapstructure:"onlinePush"`
// Add additional fields here following the same pattern for other hooks
} }
type ZooKeeper struct { 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) 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) 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 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()
}

Loading…
Cancel
Save