实现对官方 mongodb 的golang驱动的单例封装
Download and install it:
$ go get github.com/igufei/go-mongo
Import it in your code:
import "github.com/igufei/go-mongo"
import (
"fmt"
mongo "github.com/igufei/go-mongo"
"go.mongodb.org/mongo-driver/bson"
)
func init() {
mongo.MustConnect("mongodb://localhost:27017", "usermanager")
}
func main() {
value := mongo.Instance.FindOne("agent", bson.M{
"username": "gufeng",
})
fmt.Printf("%v", value)
}