Import sources from Kontor

This commit is contained in:
Thomas Peetz
2019-06-18 18:33:38 +02:00
parent fa3286c8e2
commit f326e994da
20 changed files with 1262 additions and 3 deletions
+31
View File
@@ -0,0 +1,31 @@
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)
}