Skip to content

Instantly share code, notes, and snippets.

@eamonnmcevoy
Last active March 14, 2017 12:00
Show Gist options
  • Save eamonnmcevoy/c8ac5911e46644f3bd94a406de18d8bc to your computer and use it in GitHub Desktop.
Save eamonnmcevoy/c8ac5911e46644f3bd94a406de18d8bc to your computer and use it in GitHub Desktop.
package mongo
import (
"gopkg.in/mgo.v2"
)
type Session struct {
session *mgo.Session
}
func NewSession(url string) (*Session,error) {
session, err := mgo.Dial("localhost:27017")
if err != nil {
return nil,err
}
return &Session{session}, err
}
func(s *Session) Copy() *Session {
return &Session{s.session.Copy()}
}
func(s *Session) GetCollection(db string, col string) *mgo.Collection {
return s.session.DB(db).C(col)
}
func(s *Session) Close() {
if(s.session != nil) {
s.session.Close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment