mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
当dbUri值不为空则直接使用该值
This commit is contained in:
parent
d3a38963ae
commit
6f56d19938
@ -19,6 +19,7 @@ mysql:
|
|||||||
dbMaxLifeTime: 120
|
dbMaxLifeTime: 120
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
|
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||||
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
|
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
|
||||||
dbDirect: false
|
dbDirect: false
|
||||||
dbTimeout: 10
|
dbTimeout: 10
|
||||||
|
|||||||
@ -19,6 +19,7 @@ mysql:
|
|||||||
dbMaxLifeTime: 120
|
dbMaxLifeTime: 120
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
|
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||||
dbAddress: [ openim_mongo:27017 ]
|
dbAddress: [ openim_mongo:27017 ]
|
||||||
dbDirect: false
|
dbDirect: false
|
||||||
dbTimeout: 10
|
dbTimeout: 10
|
||||||
|
|||||||
@ -66,6 +66,7 @@ type config struct {
|
|||||||
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
|
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
|
||||||
}
|
}
|
||||||
Mongo struct {
|
Mongo struct {
|
||||||
|
DBUri string `yaml:"dbUri"` // 当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"`
|
||||||
|
|||||||
@ -42,9 +42,14 @@ func init() {
|
|||||||
// mongo init
|
// mongo init
|
||||||
// "mongodb://sysop:moon@localhost/records"
|
// "mongodb://sysop:moon@localhost/records"
|
||||||
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
||||||
|
if config.Config.Mongo.DBUri != "" {
|
||||||
|
// example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
|
||||||
|
uri = config.Config.Mongo.DBUri
|
||||||
|
} 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[0], config.Config.Mongo.DBDatabase,
|
||||||
config.Config.Mongo.DBMaxPoolSize)
|
config.Config.Mongo.DBMaxPoolSize)
|
||||||
|
}
|
||||||
|
|
||||||
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||||
if err != nil{
|
if err != nil{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user