-
Notifications
You must be signed in to change notification settings - Fork 1
/
documentdb.go
43 lines (35 loc) · 1.02 KB
/
documentdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package documents
import (
"fmt"
"time"
"github.com/mdaxf/iac/logger"
)
// DocDB is the interface for document database
var DocDBCon *DocDB
// ConnectDB is the function to connect to document database
// DatabaseType: mongodb
// DatabaseConnection: mongodb://localhost:27017
// DatabaseName: iac
func ConnectDB(DatabaseType string, DatabaseConnection string, DatabaseName string) {
iLog := logger.Log{ModuleName: logger.Database, User: "System", ControllerName: "DocumentDatabase"}
startTime := time.Now()
defer func() {
elapsed := time.Since(startTime)
iLog.PerformanceWithDuration("documents.ConnectDB", elapsed)
}()
/*
defer func() {
if err := recover(); err != nil {
iLog.Error(fmt.Sprintf("There is error to documents.ConnectDB with error: %s", err))
return
}
}()
*/
if DatabaseType == "mongodb" {
var err error
DocDBCon, err = InitMongoDB(DatabaseConnection, DatabaseName)
if err != nil {
iLog.Error(fmt.Sprintf("initialize Documents Database (MongoDB) error: %s", err.Error()))
}
}
}