-
Notifications
You must be signed in to change notification settings - Fork 57
/
database.go
49 lines (43 loc) · 1.17 KB
/
database.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
44
45
46
47
48
49
package database
import (
"github.com/gin-gonic/gin"
"github.com/signalfx/tracing-examples/signalfx-tracing/signalfx-go-tracing/gin/server/models"
)
// Manager provides interface to communicate with database chosen by the user
type Manager interface {
GetBoardByID(c *gin.Context, id string) (models.Board, error)
InsertBoard(c *gin.Context, board models.Board) error
UpdateBoard(c *gin.Context, board models.Board) error
Close(c *gin.Context)
}
// Config is a type to store database connection config
type Config struct {
Driver string
Host string
Port int
Name string
ServiceName string
}
var manager Manager
// InitManager creates an instace of gifven manager type
func InitManager(conf *Config) {
if conf.Driver == "mgo" {
manager = &mgoManager{
Host: conf.Host,
Port: conf.Port,
Name: conf.Name,
ServiceName: conf.ServiceName,
}
} else if conf.Driver == "mongo" {
manager = &mongoManager{
Host: conf.Host,
Port: conf.Port,
Name: conf.Name,
ServiceName: conf.ServiceName,
}
}
}
// GetManager returns database manager instance
func GetManager() Manager {
return manager
}