Skip to content

Commit

Permalink
mongo connection now uses ENV variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonay committed Feb 22, 2015
1 parent 2d5dcf3 commit 32a3a1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions handlers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,24 @@ func Run(cfg common.Config) error {
}

func InitMongo() (*mgo.Database, *mgo.Session, error) {
session, err := mgo.Dial("localhost:27017")

uri := os.Getenv("MONGOHQ_URL")
if uri == "" {
fmt.Println("\x1b[31;1mno connection string provided\x1b[0m")
os.Exit(1)
}
db_name := os.Getenv("MONGOHQ_DB")
if db_name == "" {
fmt.Println("\x1b[31;1mno db name provided\x1b[0m")
os.Exit(1)
}
session, err := mgo.Dial(uri)
if err != nil {
colorMsg := "\x1b[31;1mMongo connection failed\x1b[0m"
log.Fatalln(colorMsg, err)
}

db := session.DB("testing")
db := session.DB(db_name)

return db, session, nil
}
Expand Down
Binary file modified okra
Binary file not shown.

0 comments on commit 32a3a1a

Please sign in to comment.