forked from pivotal-pez/cfmgo
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconnect.go
More file actions
25 lines (20 loc) · 756 Bytes
/
connect.go
File metadata and controls
25 lines (20 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// A MongoDB integration package for Cloud Foundry.
package cfmgo
import (
"fmt"
"gopkg.in/mgo.v2"
)
//Connect to the specified database and return a Collection object for the specified collection.
func Connect(dialer CollectionDialer, URI string, collectionName string) (collection Collection) {
var (
err error
dialInfo *mgo.DialInfo
)
if dialInfo, err = mgo.ParseURL(URI); err != nil || dialInfo.Database == "" {
panic(fmt.Sprintf("cannot parse given URI %s due to error: %s", URI, err.Error()))
}
if collection, err = dialer(URI, dialInfo.Database, collectionName); err != nil {
panic(fmt.Sprintf("cannot dial connection due to error: %s URI:%s col:%s db:%s", err.Error(), URI, collectionName, dialInfo.Database))
}
return
}