Simplify if statements

This commit is contained in:
Kalissaac
2020-11-23 18:38:48 -08:00
parent 4611bdac86
commit 0c0949c777

View File

@@ -34,7 +34,7 @@ func New(config ...Config) *Storage {
// Create data source name // Create data source name
var dsn = "mongodb" var dsn = "mongodb"
if cfg.Atlas == true { if cfg.Atlas {
dsn += "+srv://" dsn += "+srv://"
} else { } else {
dsn += "://" dsn += "://"
@@ -48,8 +48,9 @@ func New(config ...Config) *Storage {
if cfg.Username != "" || cfg.Password != "" { if cfg.Username != "" || cfg.Password != "" {
dsn += "@" dsn += "@"
} }
if cfg.Atlas == true { // Cannot specify port when using MongoDB Atlas
dsn += url.QueryEscape(cfg.Host) // Cannot specify port when using MongoDB Atlas if cfg.Atlas {
dsn += url.QueryEscape(cfg.Host)
} else { } else {
dsn += fmt.Sprintf("%s:%d", url.QueryEscape(cfg.Host), cfg.Port) dsn += fmt.Sprintf("%s:%d", url.QueryEscape(cfg.Host), cfg.Port)
} }