|
|
@ -30,19 +30,23 @@ func registerDBCreator(backend DBBackendType, creator dbCreator, force bool) { |
|
|
|
backends[backend] = creator |
|
|
|
} |
|
|
|
|
|
|
|
// NewDB creates a new database of type backend with the given name.
|
|
|
|
// NOTE: function panics if:
|
|
|
|
// - backend is unknown (not registered)
|
|
|
|
// - creator function, provided during registration, returns error
|
|
|
|
func NewDB(name string, backend DBBackendType, dir string) DB { |
|
|
|
dbCreator, ok := backends[backend] |
|
|
|
|
|
|
|
if !ok { |
|
|
|
var keys []string |
|
|
|
for k, _ := range backends { |
|
|
|
keys = append(keys, string(k)) |
|
|
|
keys := make([]string, len(backends)) |
|
|
|
i := 0 |
|
|
|
for k := range backends { |
|
|
|
keys[i] = string(k) |
|
|
|
i++ |
|
|
|
} |
|
|
|
panic(fmt.Sprintf("Unknown db_backend %s, expected either %s", backend, strings.Join(keys, " or "))) |
|
|
|
} |
|
|
|
|
|
|
|
db, err := dbCreator(name, dir) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
panic(fmt.Sprintf("Error initializing DB: %v", err)) |
|
|
|
} |
|
|
|