mgo

package module
v0.0.0-...-e56d606 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2018 License: MIT Imports: 3 Imported by: 0

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
}

Documentation

Index

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 连接必用后置方法

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL