Last active
March 14, 2017 12:00
-
-
Save eamonnmcevoy/c8ac5911e46644f3bd94a406de18d8bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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