mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-01 12:39:18 +08:00
fix: mongo
This commit is contained in:
parent
bbb5ef5ccc
commit
86aebfc0bd
@ -103,9 +103,9 @@ func buildMongoURI() string {
|
|||||||
maxPoolSize = fmt.Sprint(config.Config.Mongo.MaxPoolSize)
|
maxPoolSize = fmt.Sprint(config.Config.Mongo.MaxPoolSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
uriFormat := "mongodb://%s/%s?maxPoolSize=%s"
|
uriFormat := "mongodb://%s/%s?maxPoolSize=%s&authSource=admin"
|
||||||
if username != "" && password != "" {
|
if username != "" && password != "" {
|
||||||
uriFormat = "mongodb://%s:%s@%s/%s?maxPoolSize=%s"
|
uriFormat = "mongodb://%s:%s@%s/%s?maxPoolSize=%s&authSource=admin"
|
||||||
return fmt.Sprintf(uriFormat, username, password, address, database, maxPoolSize)
|
return fmt.Sprintf(uriFormat, username, password, address, database, maxPoolSize)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(uriFormat, address, database, maxPoolSize)
|
return fmt.Sprintf(uriFormat, address, database, maxPoolSize)
|
||||||
|
@ -33,10 +33,10 @@ import (
|
|||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
"gopkg.in/yaml.v3"
|
"github.com/redis/go-redis/v9"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -145,7 +145,7 @@ func getEnv(key, fallback string) string {
|
|||||||
func checkMongo() (string, error) {
|
func checkMongo() (string, error) {
|
||||||
// Use environment variables or fallback to config
|
// Use environment variables or fallback to config
|
||||||
uri := getEnv("MONGO_URI", buildMongoURI())
|
uri := getEnv("MONGO_URI", buildMongoURI())
|
||||||
|
fmt.Println("mongo uri", uri)
|
||||||
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||||
str := "ths addr is:" + strings.Join(config.Config.Mongo.Address, ",")
|
str := "ths addr is:" + strings.Join(config.Config.Mongo.Address, ",")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -171,10 +171,10 @@ func buildMongoURI() string {
|
|||||||
mongodbHosts := strings.Join(config.Config.Mongo.Address, ",")
|
mongodbHosts := strings.Join(config.Config.Mongo.Address, ",")
|
||||||
|
|
||||||
if username != "" && password != "" {
|
if username != "" && password != "" {
|
||||||
return fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d",
|
return fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d&authSource=admin",
|
||||||
username, password, mongodbHosts, database, maxPoolSize)
|
username, password, mongodbHosts, database, maxPoolSize)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("mongodb://%s/%s?maxPoolSize=%d",
|
return fmt.Sprintf("mongodb://%s/%s?maxPoolSize=%d&authSource=admin",
|
||||||
mongodbHosts, database, maxPoolSize)
|
mongodbHosts, database, maxPoolSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,6 @@ func checkMinio() (string, error) {
|
|||||||
if config.Config.Object.Enable != "minio" {
|
if config.Config.Object.Enable != "minio" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prioritize environment variables
|
// Prioritize environment variables
|
||||||
endpoint := getEnv("MINIO_ENDPOINT", config.Config.Object.Minio.Endpoint)
|
endpoint := getEnv("MINIO_ENDPOINT", config.Config.Object.Minio.Endpoint)
|
||||||
accessKeyID := getEnv("MINIO_ACCESS_KEY_ID", config.Config.Object.Minio.AccessKeyID)
|
accessKeyID := getEnv("MINIO_ACCESS_KEY_ID", config.Config.Object.Minio.AccessKeyID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user