package model
import mgo "gopkg.in/mgo.v2"
// Datastore interface describes all model methods using the MongoDB database.
type Datastore interface {
ShowUser(int) (*User, error)
}
// Database alias for mgo.Database.
type Database struct {
mgo *mgo.Database
}
// InitSession initializes a mgo Session and return the session
// object and the mgo database according to the settings in
// the config file.
func InitSession(config *Config) (*mgo.Session, *mgo.Database, error) {
s, err := mgo.Dial(config.Database.URL + ":" + config.Database.Port)
defer s.Close()
if err != nil {
return nil, nil, err
}
return s, s.DB(config.Database.DB), nil
}