mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
新增Mongo.DBUri配置
This commit is contained in:
parent
4ebf13a630
commit
57cd405033
@ -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: ""
|
||||||
dbAddress: [ openim_mongo:27017 ]
|
dbAddress: [ openim_mongo:27017 ]
|
||||||
dbDirect: false
|
dbDirect: false
|
||||||
dbTimeout: 10
|
dbTimeout: 10
|
||||||
|
|||||||
@ -20,8 +20,8 @@ var (
|
|||||||
var Config config
|
var Config config
|
||||||
|
|
||||||
type callBackConfig struct {
|
type callBackConfig struct {
|
||||||
Enable bool `yaml:"enable"`
|
Enable bool `yaml:"enable"`
|
||||||
CallbackTimeOut int `yaml:"callbackTimeOut"`
|
CallbackTimeOut int `yaml:"callbackTimeOut"`
|
||||||
CallbackFailedContinue bool `CallbackFailedContinue`
|
CallbackFailedContinue bool `CallbackFailedContinue`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ type config struct {
|
|||||||
Api struct {
|
Api struct {
|
||||||
GinPort []int `yaml:"openImApiPort"`
|
GinPort []int `yaml:"openImApiPort"`
|
||||||
}
|
}
|
||||||
CmsApi struct{
|
CmsApi struct {
|
||||||
GinPort []int `yaml:"openImCmsApiPort"`
|
GinPort []int `yaml:"openImCmsApiPort"`
|
||||||
}
|
}
|
||||||
Sdk struct {
|
Sdk struct {
|
||||||
@ -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"`
|
||||||
@ -182,12 +183,12 @@ type config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Callback struct {
|
Callback struct {
|
||||||
CallbackUrl string `yaml:"callbackUrl"`
|
CallbackUrl string `yaml:"callbackUrl"`
|
||||||
CallbackBeforeSendSingleMsg callBackConfig `yaml:"callbackbeforeSendSingleMsg"`
|
CallbackBeforeSendSingleMsg callBackConfig `yaml:"callbackbeforeSendSingleMsg"`
|
||||||
CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackAfterSendSingleMsg"`
|
CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackAfterSendSingleMsg"`
|
||||||
CallbackBeforeSendGroupMsg callBackConfig `yaml:"callbackBeforeSendGroupMsg"`
|
CallbackBeforeSendGroupMsg callBackConfig `yaml:"callbackBeforeSendGroupMsg"`
|
||||||
CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"`
|
CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"`
|
||||||
CallbackWordFilter callBackConfig `yaml:"callbackWordFilter"`
|
CallbackWordFilter callBackConfig `yaml:"callbackWordFilter"`
|
||||||
} `yaml:"callback"`
|
} `yaml:"callback"`
|
||||||
Notification struct {
|
Notification struct {
|
||||||
///////////////////////group/////////////////////////////
|
///////////////////////group/////////////////////////////
|
||||||
|
|||||||
@ -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