get mongodb configuration from env

This commit is contained in:
lealife
2015-09-09 10:10:24 +08:00
parent afbda7bfb2
commit 4f2d7b8cd0
2 changed files with 10 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
. "github.com/leanote/leanote/app/lea"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"strings"
)
// Init mgo and the common DAO
@ -62,6 +63,14 @@ func Init(url, dbname string) {
config := revel.Config
if url == "" {
url, ok = config.String("db.url")
if !ok {
url, ok = config.String("db.urlEnv")
}
if ok {
// get dbname from url
urls := strings.Split(url, "/")
dbname = urls[len(urls)-1]
}
}
if dbname == "" {
dbname, _ = config.String("db.dbname")