config file update

This commit is contained in:
Gordon 2022-06-17 10:50:15 +08:00
parent 365d282119
commit fd256a6c28
4 changed files with 25 additions and 25 deletions

View File

@ -23,7 +23,7 @@ mysql:
mongo: mongo:
dbUri: ""#当dbUri值不为空则直接使用该值 dbUri: ""#当dbUri值不为空则直接使用该值
dbAddress: [ 127.0.0.1:37017 ] #mongo地址 目前仅支持单机,默认即可 dbAddress: 127.0.0.1:37017 #单机时为mongo地址使用分片集群时为mongos地址 默认即可
dbDirect: false dbDirect: false
dbTimeout: 60 dbTimeout: 60
dbDatabase: openIM #mongo db 默认即可 dbDatabase: openIM #mongo db 默认即可
@ -34,12 +34,12 @@ mongo:
dbRetainChatRecords: 3650 #mongo保存离线消息时间根据需求修改 dbRetainChatRecords: 3650 #mongo保存离线消息时间根据需求修改
redis: redis:
dbAddress: 127.0.0.1:16379 #redis地址 目前仅支持单机,默认即可 dbAddress: [ 127.0.0.1:16379 ] #redis地址 单机填写一个地址即可使用redis集群时候填写集群中多个节点地址主从地址都可以填写增加容灾能力,默认即可
dbMaxIdle: 128 dbMaxIdle: 128
dbMaxActive: 0 dbMaxActive: 0
dbIdleTimeout: 120 dbIdleTimeout: 120
dbPassWord: openIM #redis密码 建议修改 dbPassWord: openIM #redis密码 建议修改
enableCluster: false enableCluster: false #如果外部redis以集群方式启动需要打开此开关
kafka: kafka:
ws2mschat: ws2mschat:

View File

@ -85,24 +85,24 @@ type config struct {
DBMaxLifeTime int `yaml:"dbMaxLifeTime"` DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
} }
Mongo struct { Mongo struct {
DBUri string `yaml:"dbUri"` DBUri string `yaml:"dbUri"`
DBAddress []string `yaml:"dbAddress"` DBAddress string `yaml:"dbAddress"`
DBDirect bool `yaml:"dbDirect"` DBDirect bool `yaml:"dbDirect"`
DBTimeout int `yaml:"dbTimeout"` DBTimeout int `yaml:"dbTimeout"`
DBDatabase string `yaml:"dbDatabase"` DBDatabase string `yaml:"dbDatabase"`
DBSource string `yaml:"dbSource"` DBSource string `yaml:"dbSource"`
DBUserName string `yaml:"dbUserName"` DBUserName string `yaml:"dbUserName"`
DBPassword string `yaml:"dbPassword"` DBPassword string `yaml:"dbPassword"`
DBMaxPoolSize int `yaml:"dbMaxPoolSize"` DBMaxPoolSize int `yaml:"dbMaxPoolSize"`
DBRetainChatRecords int `yaml:"dbRetainChatRecords"` DBRetainChatRecords int `yaml:"dbRetainChatRecords"`
} }
Redis struct { Redis struct {
DBAddress string `yaml:"dbAddress"` DBAddress []string `yaml:"dbAddress"`
DBMaxIdle int `yaml:"dbMaxIdle"` DBMaxIdle int `yaml:"dbMaxIdle"`
DBMaxActive int `yaml:"dbMaxActive"` DBMaxActive int `yaml:"dbMaxActive"`
DBIdleTimeout int `yaml:"dbIdleTimeout"` DBIdleTimeout int `yaml:"dbIdleTimeout"`
DBPassWord string `yaml:"dbPassWord"` DBPassWord string `yaml:"dbPassWord"`
EnableCluster bool `yaml:"enableCluster"` EnableCluster bool `yaml:"enableCluster"`
} }
RpcPort struct { RpcPort struct {
OpenImUserPort []int `yaml:"openImUserPort"` OpenImUserPort []int `yaml:"openImUserPort"`

View File

@ -56,11 +56,11 @@ func init() {
uri = config.Config.Mongo.DBUri uri = config.Config.Mongo.DBUri
} else { } else {
if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" { if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" {
uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d", config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword, config.Config.Mongo.DBAddress[0], uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d", config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword, config.Config.Mongo.DBAddress,
config.Config.Mongo.DBDatabase, config.Config.Mongo.DBMaxPoolSize) config.Config.Mongo.DBDatabase, config.Config.Mongo.DBMaxPoolSize)
} else { } else {
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d", uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase, config.Config.Mongo.DBAddress, config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize) config.Config.Mongo.DBMaxPoolSize)
} }
} }
@ -123,7 +123,7 @@ func init() {
defer cancel() defer cancel()
if config.Config.Redis.EnableCluster { if config.Config.Redis.EnableCluster {
DB.rdb = go_redis.NewClusterClient(&go_redis.ClusterOptions{ DB.rdb = go_redis.NewClusterClient(&go_redis.ClusterOptions{
Addrs: []string{config.Config.Redis.DBAddress}, Addrs: config.Config.Redis.DBAddress,
PoolSize: 50, PoolSize: 50,
}) })
_, err = DB.rdb.Ping(ctx).Result() _, err = DB.rdb.Ping(ctx).Result()
@ -132,7 +132,7 @@ func init() {
} }
} else { } else {
DB.rdb = go_redis.NewClient(&go_redis.Options{ DB.rdb = go_redis.NewClient(&go_redis.Options{
Addr: config.Config.Redis.DBAddress, Addr: config.Config.Redis.DBAddress[0],
Password: config.Config.Redis.DBPassWord, // no password set Password: config.Config.Redis.DBPassWord, // no password set
DB: 0, // use default DB DB: 0, // use default DB
PoolSize: 100, // 连接池大小 PoolSize: 100, // 连接池大小

View File

@ -17,11 +17,11 @@ func init() {
uri = config.Config.Mongo.DBUri uri = config.Config.Mongo.DBUri
} else { } else {
if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" { if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" {
uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d", config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword, config.Config.Mongo.DBAddress[0], uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d", config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword, config.Config.Mongo.DBAddress,
config.Config.Mongo.DBDatabase, config.Config.Mongo.DBMaxPoolSize) config.Config.Mongo.DBDatabase, config.Config.Mongo.DBMaxPoolSize)
} else { } else {
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d", uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase, config.Config.Mongo.DBAddress, config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize) config.Config.Mongo.DBMaxPoolSize)
} }
} }