mirror of
https://github.com/gofiber/storage.git
synced 2025-10-11 03:20:26 +08:00
Add ability to supply Mongo connection uri
This commit is contained in:
@@ -33,26 +33,33 @@ func New(config ...Config) *Storage {
|
||||
cfg := configDefault(config...)
|
||||
|
||||
// Create data source name
|
||||
var dsn = "mongodb"
|
||||
if cfg.Atlas {
|
||||
dsn += "+srv://"
|
||||
var dsn string
|
||||
|
||||
// Check if user supplied connection string
|
||||
if cfg.Connection != "" {
|
||||
dsn = cfg.Connection
|
||||
} else {
|
||||
dsn += "://"
|
||||
}
|
||||
if cfg.Username != "" {
|
||||
dsn += url.QueryEscape(cfg.Username)
|
||||
}
|
||||
if cfg.Password != "" {
|
||||
dsn += ":" + cfg.Password
|
||||
}
|
||||
if cfg.Username != "" || cfg.Password != "" {
|
||||
dsn += "@"
|
||||
}
|
||||
// Cannot specify port when using MongoDB Atlas
|
||||
if cfg.Atlas {
|
||||
dsn += url.QueryEscape(cfg.Host)
|
||||
} else {
|
||||
dsn += fmt.Sprintf("%s:%d", url.QueryEscape(cfg.Host), cfg.Port)
|
||||
dsn = "mongodb"
|
||||
if cfg.Atlas {
|
||||
dsn += "+srv://"
|
||||
} else {
|
||||
dsn += "://"
|
||||
}
|
||||
if cfg.Username != "" {
|
||||
dsn += url.QueryEscape(cfg.Username)
|
||||
}
|
||||
if cfg.Password != "" {
|
||||
dsn += ":" + cfg.Password
|
||||
}
|
||||
if cfg.Username != "" || cfg.Password != "" {
|
||||
dsn += "@"
|
||||
}
|
||||
// Cannot specify port when using MongoDB Atlas
|
||||
if cfg.Atlas {
|
||||
dsn += url.QueryEscape(cfg.Host)
|
||||
} else {
|
||||
dsn += fmt.Sprintf("%s:%d", url.QueryEscape(cfg.Host), cfg.Port)
|
||||
}
|
||||
}
|
||||
|
||||
// Set mongo options
|
||||
|
Reference in New Issue
Block a user