dpmgo

package module
v0.0.0-...-58eae50 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2016 License: MIT Imports: 4 Imported by: 0

README

Defer Panic mgo add-on

wercker status

GoDoc

Defer Panic mgo add-on pkg

Many deferpanic users use mgo. This is the first attempt to start adding support. Much is left to do and this will probably change dramatically in the near future.

Currently the DeferPanic wrapper operates at the collection level.

package main

import (
	"fmt"
	"github.com/deferpanic/deferclient/deferstats"
	"github.com/deferpanic/dpmgo"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
	"log"
	"time"
)

type Person struct {
	Name  string
	Phone string
}

func main() {
  // these next 2 lines capture stats
	dps := deferstats.NewClient("v00L0K6CdKjE4QwX5DL1iiODxovAHUfo")
	go dps.CaptureStats()

	session, err := mgo.Dial("127.0.0.1")
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)

  // these next 2 lines wrap your collection
	_c := session.DB("test").C("people")
	c := dpmgo.NewCollection(_c)

	err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
		&Person{"Cla", "+55 53 8402 8510"})
	if err != nil {
		log.Fatal(err)
	}

	result := Person{}
	err = c.Find(bson.M{"name": "Ale"}).One(&result)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Phone:", result.Phone)

	time.Sleep(200 * time.Second)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DpMgo

type DpMgo struct {
	Other *mgo.Collection
}

func NewCollection

func NewCollection(m *mgo.Collection) *DpMgo

func (*DpMgo) EnsureIndexKey

func (db *DpMgo) EnsureIndexKey(key ...string) error

func (*DpMgo) Find

func (db *DpMgo) Find(query interface{}) *mgo.Query

func (*DpMgo) Insert

func (db *DpMgo) Insert(docs ...interface{}) error

Jump to

Keyboard shortcuts

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