From fd256a6c28ec0893bc55e773e0fe9d4007d5b33b Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 17 Jun 2022 10:50:15 +0800 Subject: [PATCH] config file update --- config/config.yaml | 6 +++--- pkg/common/config/config.go | 32 ++++++++++++++++---------------- pkg/common/db/model.go | 8 ++++---- test/mongo/cmd/main.go | 4 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 3143f3a0b..17991eef1 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -23,7 +23,7 @@ mysql: mongo: dbUri: ""#当dbUri值不为空则直接使用该值 - dbAddress: [ 127.0.0.1:37017 ] #mongo地址 目前仅支持单机,默认即可 + dbAddress: 127.0.0.1:37017 #单机时为mongo地址,使用分片集群时,为mongos地址 默认即可 dbDirect: false dbTimeout: 60 dbDatabase: openIM #mongo db 默认即可 @@ -34,12 +34,12 @@ mongo: dbRetainChatRecords: 3650 #mongo保存离线消息时间(天),根据需求修改 redis: - dbAddress: 127.0.0.1:16379 #redis地址 目前仅支持单机,默认即可 + dbAddress: [ 127.0.0.1:16379 ] #redis地址 单机时,填写一个地址即可,使用redis集群时候,填写集群中多个节点地址(主从地址都可以填写,增加容灾能力),默认即可 dbMaxIdle: 128 dbMaxActive: 0 dbIdleTimeout: 120 dbPassWord: openIM #redis密码 建议修改 - enableCluster: false + enableCluster: false #如果外部redis以集群方式启动,需要打开此开关 kafka: ws2mschat: diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index de0d1597e..39ee0f9fb 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -85,24 +85,24 @@ type config struct { DBMaxLifeTime int `yaml:"dbMaxLifeTime"` } Mongo struct { - DBUri string `yaml:"dbUri"` - DBAddress []string `yaml:"dbAddress"` - DBDirect bool `yaml:"dbDirect"` - DBTimeout int `yaml:"dbTimeout"` - DBDatabase string `yaml:"dbDatabase"` - DBSource string `yaml:"dbSource"` - DBUserName string `yaml:"dbUserName"` - DBPassword string `yaml:"dbPassword"` - DBMaxPoolSize int `yaml:"dbMaxPoolSize"` - DBRetainChatRecords int `yaml:"dbRetainChatRecords"` + DBUri string `yaml:"dbUri"` + DBAddress string `yaml:"dbAddress"` + DBDirect bool `yaml:"dbDirect"` + DBTimeout int `yaml:"dbTimeout"` + DBDatabase string `yaml:"dbDatabase"` + DBSource string `yaml:"dbSource"` + DBUserName string `yaml:"dbUserName"` + DBPassword string `yaml:"dbPassword"` + DBMaxPoolSize int `yaml:"dbMaxPoolSize"` + DBRetainChatRecords int `yaml:"dbRetainChatRecords"` } Redis struct { - DBAddress string `yaml:"dbAddress"` - DBMaxIdle int `yaml:"dbMaxIdle"` - DBMaxActive int `yaml:"dbMaxActive"` - DBIdleTimeout int `yaml:"dbIdleTimeout"` - DBPassWord string `yaml:"dbPassWord"` - EnableCluster bool `yaml:"enableCluster"` + DBAddress []string `yaml:"dbAddress"` + DBMaxIdle int `yaml:"dbMaxIdle"` + DBMaxActive int `yaml:"dbMaxActive"` + DBIdleTimeout int `yaml:"dbIdleTimeout"` + DBPassWord string `yaml:"dbPassWord"` + EnableCluster bool `yaml:"enableCluster"` } RpcPort struct { OpenImUserPort []int `yaml:"openImUserPort"` diff --git a/pkg/common/db/model.go b/pkg/common/db/model.go index bc8af133d..61912b670 100644 --- a/pkg/common/db/model.go +++ b/pkg/common/db/model.go @@ -56,11 +56,11 @@ func init() { uri = config.Config.Mongo.DBUri } else { 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) } else { 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) } } @@ -123,7 +123,7 @@ func init() { defer cancel() if config.Config.Redis.EnableCluster { DB.rdb = go_redis.NewClusterClient(&go_redis.ClusterOptions{ - Addrs: []string{config.Config.Redis.DBAddress}, + Addrs: config.Config.Redis.DBAddress, PoolSize: 50, }) _, err = DB.rdb.Ping(ctx).Result() @@ -132,7 +132,7 @@ func init() { } } else { 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 DB: 0, // use default DB PoolSize: 100, // 连接池大小 diff --git a/test/mongo/cmd/main.go b/test/mongo/cmd/main.go index 2a8d41523..e2c6e99b8 100644 --- a/test/mongo/cmd/main.go +++ b/test/mongo/cmd/main.go @@ -17,11 +17,11 @@ func init() { uri = config.Config.Mongo.DBUri } else { 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) } else { 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) } }