Skip to content
This repository was archived by the owner on Jul 16, 2021. It is now read-only.

Commit e3f08cb

Browse files
authored
add --mongo-url CLI option to override database URL (#402)
1 parent d7f2f77 commit e3f08cb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/api/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"flag"
45
"net/http"
56
"os"
67
"time"
@@ -146,6 +147,14 @@ func main() {
146147
log.WithError(err).Fatal("unable to load configuration")
147148
}
148149

150+
dbURL := flag.String("mongo-url", "", "MongoDB URL (see https://godoc.org/labix.org/v2/mgo#Dial for format)")
151+
flag.Parse()
152+
153+
// Override database URL if given as CLI option
154+
if *dbURL != "" {
155+
conf.Mongo.URL = *dbURL
156+
}
157+
149158
dbSession, err := datastore.NewSession(conf.Mongo)
150159
if err != nil {
151160
log.WithFields(log.Fields{"host": conf.Mongo.URL}).Fatal(err)

0 commit comments

Comments
 (0)