-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorm.go
42 lines (35 loc) · 856 Bytes
/
storm.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
/*
STORM is Semantically Terse Object Relational Mapping for Go
*/
package storm
import (
"errors"
"github.com/brendensoares/storm/driver"
)
var (
drivers = make(map[string]driver.Driver)
activeDriver string
)
func RegisterDriver(newDriver driver.Driver) {
if _, duplicate := drivers[newDriver.Name()]; duplicate {
panic("Data driver already added")
}
drivers[newDriver.Name()] = newDriver
}
func Connect(driverName string, driverConfig string) (connectError error) {
if driverName == "" || driverConfig == "" {
// Failure
return errors.New("Invalid configuration given")
} else {
// Success
// TODO: check that the driver is ready to receive requests
if connectError = drivers[driverName].Open(driverConfig); connectError != nil {
// Failure
return
} else {
// Success
activeDriver = driverName
}
}
return
}