Minor comments

This commit is contained in:
Arpit Mohan 2019-02-27 09:44:02 +05:30
parent 13a0247fd7
commit eb2af8e534

View File

@ -1,15 +1,12 @@
package storage
import (
"database/sql"
"fmt"
"log"
"github.com/jinzhu/gorm"
)
var db *sql.DB
var StorageEngine DataStore
// 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)
// 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) {
if factory == nil {
log.Panicf("Datastore factory %s does not exist.", name)
@ -33,10 +36,8 @@ func Register(name string, factory DataStoreFactory) {
datastoreFactories[name] = factory
}
func init() {
Register("postgres", InitPostgresDb)
}
// CreateDatastore initializes a datastore with connection pooling for a specific data storage name
// This name must have been registered with datastoreFactories when the storage package is initialized
func CreateDatastore(name string) (DataStore, error) {
engine, ok := datastoreFactories[name]
if !ok {