Change config to use local/storage

This commit is contained in:
breel
2020-08-27 12:32:33 -06:00
parent bb9b91eef5
commit 3a99bf5e33
7 changed files with 201 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package driver
import (
"context"
"local/dndex/config"
"local/storage"
"strings"
"go.mongodb.org/mongo-driver/bson"
@@ -18,9 +19,12 @@ type Driver interface {
func New(path ...string) Driver {
if len(path) == 0 {
path = []string{config.New().DBURI}
path = config.New().Driver
}
switch strings.ToLower(config.New().DriverType) {
if t := storage.TypeFromString(path[0]); t >= 0 {
return NewStorage(path...)
}
switch strings.ToLower(config.New().Driver[0]) {
case "map":
return NewMap()
case "mongo":
@@ -28,5 +32,5 @@ func New(path ...string) Driver {
case "boltdb":
return NewBoltDB(path[0])
}
panic("unknown driver type " + strings.ToLower(config.New().DriverType))
panic("unknown driver type " + strings.ToLower(config.New().Driver[0]))
}