Skip to content

Commit

Permalink
mongo connection successful
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonay committed Feb 22, 2015
1 parent 6ac8e65 commit cb256ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions handlers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func getConfig(c *cli.Context) (common.Config, error) {
func Run(cfg common.Config) error {

// initialize mongo
mongodb, session, err := InitMongo()
mongodb, err := InitMongo()
if err != nil {
colorMsg := "\x1b[31;1mMongoDB failed to initialize\x1b[0m"
log.Fatalln(colorMsg, err)
Expand All @@ -43,8 +43,7 @@ func Run(cfg common.Config) error {
// defer mongodb.Close()

doWorkResource := &DoWorkResource{
mongo: mongodb,
session: session,
mongo: mongodb,
}

r := gin.New()
Expand Down Expand Up @@ -96,7 +95,7 @@ func Run(cfg common.Config) error {
return nil
}

func InitMongo() (*mgo.Database, *mgo.Session, error) {
func InitMongo() (*mgo.Database, error) {

uri := os.Getenv("MONGOHQ_URL")
fmt.Println("uri: ", uri)
Expand All @@ -110,15 +109,18 @@ func InitMongo() (*mgo.Database, *mgo.Session, error) {
fmt.Println("\x1b[31;1mno db name provided\x1b[0m")
os.Exit(1)
}
session, err := mgo.Dial(uri)
url := uri + "/" + db_name
fmt.Println("uri: ", url)
session, err := mgo.Dial(url)
if err != nil {
colorMsg := "\x1b[31;1mMongo connection failed\x1b[0m"
log.Fatalln(colorMsg, err)
}
defer session.Close()

db := session.DB(db_name)

return db, session, nil
return db, nil
}

var Commands = []cli.Command{
Expand Down
Binary file modified okra
Binary file not shown.

0 comments on commit cb256ce

Please sign in to comment.