README ¶ mgo 够浪用 globalsign/mgo 连接 mongodb 的实例 usage go-example package main import ( "os" "github.com/CARVIN94/mgo" ) func init() { mgo.Connect(&mgo.Config{ Hosts: "localhost:27017", Database: "mqtt", // Timeout: time.Second * 60, }) } func main() { quit := make(chan os.Signal) <-quit } Expand ▾ Collapse ▴ Documentation ¶ Index ¶ func Connect(config *Config) func GetDatabase() string type Config type Task func Collection(database string, collection string) Task func (task *Task) EnableNotFound() func (task *Task) End() Constants ¶ This section is empty. Variables ¶ This section is empty. Functions ¶ func Connect ¶ func Connect(config *Config) Connect 初始化并连接数据库 func GetDatabase ¶ func GetDatabase() string GetDatabase 获取数据库名称 Types ¶ type Config ¶ type Config struct { Hosts string Database string UserName string Password string Timeout time.Duration } Config 数据库基础配置 type Task ¶ type Task struct { *mgo.Collection } Task 查询任务模型 func Collection ¶ func Collection(database string, collection string) Task Collection 连接必用前置方法 func (*Task) EnableNotFound ¶ func (task *Task) EnableNotFound() EnableNotFound 处理没有搜索到数据的情况 func (*Task) End ¶ func (task *Task) End() End 连接必用后置方法 Source Files ¶ View all Source files mgo.go Click to show internal directories. Click to hide internal directories.