Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcs
dfss
Commits
d1fe9083
Commit
d1fe9083
authored
Jan 22, 2016
by
Axel
Browse files
US-177: Correcting mgdb lib
parent
65c3cf1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
mgdb/manager.go
View file @
d1fe9083
...
...
@@ -33,12 +33,12 @@ type MongoManager struct {
Collections
map
[
string
]
*
MongoCollection
}
// NewManager a new Manager, the environment variable
MONGOHQ_URL
needs to be set
// NewManager a new Manager, the environment variable
'connection'
needs to be set
// up with mongo uri, else it throws an error
func
NewManager
(
database
string
)
(
*
MongoManager
,
error
)
{
uri
:=
os
.
Getenv
(
"MGDB_URL"
)
func
NewManager
(
database
,
connection
string
)
(
*
MongoManager
,
error
)
{
uri
:=
os
.
Getenv
(
connection
)
if
uri
==
""
{
err
:=
newErrorConnection
(
"No uri provided, please set the
MONGOHG_URL
to connect to mongo"
)
err
:=
newErrorConnection
(
"No uri provided, please set the
"
+
connection
+
" environment variable
to connect to mongo"
)
return
nil
,
err
}
...
...
mgdb/manager_test.go
View file @
d1fe9083
...
...
@@ -19,20 +19,22 @@ type hand struct {
CardTwo
card
`key:"card_two" bson:"card_two"`
}
const
defaultDBUrl
=
"MGDB_URL"
var
collection
*
MongoCollection
var
manager
*
MongoManager
var
err
error
func
TestMain
(
m
*
testing
.
M
)
{
// Setup
fmt
.
Println
(
"Try to connect to : "
+
os
.
Getenv
(
"MGDB_URL"
))
fmt
.
Println
(
"Try to connect to : "
+
os
.
Getenv
(
defaultDBUrl
))
db
:=
os
.
Getenv
(
"DFSS_TEST"
)
db
:=
os
.
Getenv
(
defaultDBUrl
)
if
db
==
""
{
db
=
"demo"
}
manager
,
err
=
NewManager
(
db
)
manager
,
err
=
NewManager
(
db
,
defaultDBUrl
)
collection
=
manager
.
Get
(
"demo"
)
...
...
@@ -185,7 +187,7 @@ func ExampleMongoManager() {
}
//Initializes a MongoManager for the 'demo' database
manager
,
err
:=
NewManager
(
"demo"
)
manager
,
err
:=
NewManager
(
"demo"
,
defaultDBUrl
)
if
err
!=
nil
{
/* Handle error */
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment