Files
kalorienmanager/pkg/dao/database.go
T
2019-06-18 18:33:38 +02:00

32 lines
751 B
Go

package dao
import (
"log"
mgo "gopkg.in/mgo.v2"
)
// BaseDAO definess the connection parameters to a MongoDB instance.
type BaseDAO struct {
Server string
Database string
MongoDb *mgo.Database
}
var (
// KalorienmanagerDb has the database connection to the productive MongoDB instance.
KalorienmanagerDb = BaseDAO{Server: "localhost", Database: "kalorienmanager"}
// TestDb has the database connection to the test MongoDB instance.
TestDb = BaseDAO{Server: "localhost", Database: "kalorienmanager_test"}
)
// Connect instantiates the database session.
func (m *BaseDAO) Connect() {
session, err := mgo.Dial(m.Server)
if err != nil {
//util.PrintDebug("Connect: %v", err)
log.Fatal(err)
}
m.MongoDb = session.DB(m.Database)
}