Minor comments
This commit is contained in:
parent
13a0247fd7
commit
eb2af8e534
|
|
@ -1,15 +1,12 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db *sql.DB
|
|
||||||
|
|
||||||
var StorageEngine DataStore
|
var StorageEngine DataStore
|
||||||
|
|
||||||
// DataStore defines the interface that all db implementations must implement.
|
// DataStore defines the interface that all db implementations must implement.
|
||||||
|
|
@ -22,6 +19,12 @@ type DataStoreFactory func() (DataStore, error)
|
||||||
|
|
||||||
var datastoreFactories = make(map[string]DataStoreFactory)
|
var datastoreFactories = make(map[string]DataStoreFactory)
|
||||||
|
|
||||||
|
// Constructor for the storage package
|
||||||
|
func init() {
|
||||||
|
Register("postgres", InitPostgresDb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register adds the DataStoreFactory against a name to the registry incase it's not present
|
||||||
func Register(name string, factory DataStoreFactory) {
|
func Register(name string, factory DataStoreFactory) {
|
||||||
if factory == nil {
|
if factory == nil {
|
||||||
log.Panicf("Datastore factory %s does not exist.", name)
|
log.Panicf("Datastore factory %s does not exist.", name)
|
||||||
|
|
@ -33,10 +36,8 @@ func Register(name string, factory DataStoreFactory) {
|
||||||
datastoreFactories[name] = factory
|
datastoreFactories[name] = factory
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// CreateDatastore initializes a datastore with connection pooling for a specific data storage name
|
||||||
Register("postgres", InitPostgresDb)
|
// This name must have been registered with datastoreFactories when the storage package is initialized
|
||||||
}
|
|
||||||
|
|
||||||
func CreateDatastore(name string) (DataStore, error) {
|
func CreateDatastore(name string) (DataStore, error) {
|
||||||
engine, ok := datastoreFactories[name]
|
engine, ok := datastoreFactories[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user