Skip to content

Commit

Permalink
edit: config
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXu committed Apr 18, 2016
1 parent 8c2876e commit 7ff2cc2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"MongoDBUrl":"mongodb://localhost:27017/",
"Emails":[
{"Address":"[email protected]", "Password":"testing","Host":"mail.google.com","Port":"465"},
{"Address":"[email protected]", "Password":"testing","Host":"mail.google.com","Port":"465"}
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var (
)

type Configuration struct{
MongoDBUrl string
Emails []Email
Jwtkey string
}
Expand Down Expand Up @@ -50,4 +51,8 @@ func GetAnEmail() *Email {
return nil
}
return &(Config.Emails[0])
}

func GetMongoDBUrl() string{
return Config.MongoDBUrl
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

func init() {
mongodb.Connect()
config.GetConfig()
mongodb.Connect()
}

func main() {
Expand Down
6 changes: 4 additions & 2 deletions mongodb/mongodb.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package mongodb

import (
"os"

"fmt"
"gopkg.in/mgo.v2"
Config "goServe/config"
)

var (
Expand All @@ -20,7 +21,8 @@ const (
)

func Connect() {
uri := os.Getenv("MONGODB_URL")
//uri := os.Getenv("MONGODB_URL")
uri := Config.GetMongoDBUrl()
if len(uri)==0 {
uri = MongoDBUrl
}
Expand Down

0 comments on commit 7ff2cc2

Please sign in to comment.