1.xxdb.go程序内容如下
package xxdb
import (
"../xxio"
"fmt"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
const URL = "127.0.0.1:27017"
// dial to db
func Dial(db, collection string) (*mgo.Session, *mgo.Collection, error) {
var ses *mgo.Session
var col *mgo.Collection
var err error
if ses, err = mgo.Dial(URL); err != nil {
return nil, nil, xxerr("Dial", "", err)
}