switch to mongodb uri in config

This commit is contained in:
Arnaud Delcasse 2023-04-03 20:32:06 +02:00
parent a76c0412a3
commit c96b6ed943
1 changed files with 6 additions and 1 deletions

View File

@ -19,13 +19,18 @@ type MongoDBStorage struct {
func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
var (
mongodb_uri = cfg.GetString("storage.db.mongodb.uri")
mongodb_host = cfg.GetString("storage.db.mongodb.host")
mongodb_port = cfg.GetString("storage.db.mongodb.port")
mongodb_dbname = cfg.GetString("storage.db.mongodb.db_name")
mongodb_users = cfg.GetString("storage.db.mongodb.collections.users")
)
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://" + mongodb_host + ":" + mongodb_port))
if mongodb_uri == "" {
mongodb_uri = fmt.Sprintf("mongodb://%s:%s/%s", mongodb_host, mongodb_port, mongodb_dbname)
}
client, err := mongo.NewClient(options.Client().ApplyURI(mongodb_uri))
if err != nil {
return MongoDBStorage{}, err
}