split out test
parent
10e02bac31
commit
b79cb97ba6
45
db.go
45
db.go
|
|
@ -2,7 +2,6 @@ package storage
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
|
|
@ -13,49 +12,6 @@ type DB interface {
|
|||
|
||||
var DefaultNamespace = "namespace"
|
||||
|
||||
type Type int
|
||||
|
||||
const (
|
||||
MAP = Type(iota)
|
||||
BOLT = Type(iota)
|
||||
CACHE = Type(iota)
|
||||
LEVELDB = Type(iota)
|
||||
MEMCACHE = Type(iota)
|
||||
MEMCACHECLUSTER = Type(iota)
|
||||
MONGO = Type(iota)
|
||||
)
|
||||
|
||||
func (t Type) String() string {
|
||||
switch t {
|
||||
case MAP:
|
||||
return "map"
|
||||
case BOLT:
|
||||
return "bolt"
|
||||
case CACHE:
|
||||
return "cache"
|
||||
case LEVELDB:
|
||||
return "leveldb"
|
||||
case MEMCACHE:
|
||||
return "memcache"
|
||||
case MEMCACHECLUSTER:
|
||||
return "memcachecluster"
|
||||
case MONGO:
|
||||
return "mongo"
|
||||
}
|
||||
return "<unknown>"
|
||||
}
|
||||
|
||||
func TypeFromString(key string) Type {
|
||||
key = strings.ToLower(key)
|
||||
for i := 0; i < 30; i++ {
|
||||
t := Type(i)
|
||||
if t.String() == key {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return Type(-1)
|
||||
}
|
||||
|
||||
func New(key Type, params ...string) (db DB, err error) {
|
||||
defer func() {
|
||||
if i := recover(); i != nil {
|
||||
|
|
@ -66,6 +22,7 @@ func New(key Type, params ...string) (db DB, err error) {
|
|||
switch key {
|
||||
case MAP:
|
||||
db = NewMap()
|
||||
err = nil
|
||||
case BOLT:
|
||||
db, err = NewBolt(params[0])
|
||||
case CACHE:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Type int
|
||||
|
||||
const (
|
||||
MAP = Type(iota)
|
||||
BOLT = Type(iota)
|
||||
CACHE = Type(iota)
|
||||
LEVELDB = Type(iota)
|
||||
MEMCACHE = Type(iota)
|
||||
MEMCACHECLUSTER = Type(iota)
|
||||
MONGO = Type(iota)
|
||||
)
|
||||
|
||||
func (t Type) String() string {
|
||||
switch t {
|
||||
case MAP:
|
||||
return "map"
|
||||
case BOLT:
|
||||
return "bolt"
|
||||
case CACHE:
|
||||
return "cache"
|
||||
case LEVELDB:
|
||||
return "leveldb"
|
||||
case MEMCACHE:
|
||||
return "memcache"
|
||||
case MEMCACHECLUSTER:
|
||||
return "memcachecluster"
|
||||
case MONGO:
|
||||
return "mongo"
|
||||
}
|
||||
return "<unknown>"
|
||||
}
|
||||
|
||||
func TypeFromString(key string) Type {
|
||||
key = strings.ToLower(key)
|
||||
for i := 0; i < 30; i++ {
|
||||
t := Type(i)
|
||||
if t.String() == key {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return Type(-1)
|
||||
}
|
||||
Loading…
Reference in New Issue