当dbUri值不为空则直接使用该值

pull/174/head
mashouyue's m1max 4 years ago
parent d3a38963ae
commit 6f56d19938

@ -19,6 +19,7 @@ mysql:
dbMaxLifeTime: 120
mongo:
dbUri: ""#当dbUri值不为空则直接使用该值
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
dbDirect: false
dbTimeout: 10

@ -19,6 +19,7 @@ mysql:
dbMaxLifeTime: 120
mongo:
dbUri: ""#当dbUri值不为空则直接使用该值
dbAddress: [ openim_mongo:27017 ]
dbDirect: false
dbTimeout: 10

@ -20,8 +20,8 @@ var (
var Config config
type callBackConfig struct {
Enable bool `yaml:"enable"`
CallbackTimeOut int `yaml:"callbackTimeOut"`
Enable bool `yaml:"enable"`
CallbackTimeOut int `yaml:"callbackTimeOut"`
CallbackFailedContinue bool `CallbackFailedContinue`
}
@ -31,7 +31,7 @@ type config struct {
Api struct {
GinPort []int `yaml:"openImApiPort"`
}
CmsApi struct{
CmsApi struct {
GinPort []int `yaml:"openImCmsApiPort"`
}
Sdk struct {
@ -66,6 +66,7 @@ type config struct {
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
}
Mongo struct {
DBUri string `yaml:"dbUri"` // 当dbUri值不为空则直接使用该值
DBAddress []string `yaml:"dbAddress"`
DBDirect bool `yaml:"dbDirect"`
DBTimeout int `yaml:"dbTimeout"`
@ -182,12 +183,12 @@ type config struct {
}
Callback struct {
CallbackUrl string `yaml:"callbackUrl"`
CallbackUrl string `yaml:"callbackUrl"`
CallbackBeforeSendSingleMsg callBackConfig `yaml:"callbackbeforeSendSingleMsg"`
CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackAfterSendSingleMsg"`
CallbackBeforeSendGroupMsg callBackConfig `yaml:"callbackBeforeSendGroupMsg"`
CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"`
CallbackWordFilter callBackConfig `yaml:"callbackWordFilter"`
CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackAfterSendSingleMsg"`
CallbackBeforeSendGroupMsg callBackConfig `yaml:"callbackBeforeSendGroupMsg"`
CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"`
CallbackWordFilter callBackConfig `yaml:"callbackWordFilter"`
} `yaml:"callback"`
Notification struct {
///////////////////////group/////////////////////////////

@ -42,9 +42,14 @@ func init() {
// mongo init
// "mongodb://sysop:moon@localhost/records"
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
config.Config.Mongo.DBAddress[0],config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize)
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",
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize)
}
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err != nil{

Loading…
Cancel
Save