split out test
parent
10e02bac31
commit
b79cb97ba6
45
db.go
45
db.go
|
|
@ -2,7 +2,6 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DB interface {
|
type DB interface {
|
||||||
|
|
@ -13,49 +12,6 @@ type DB interface {
|
||||||
|
|
||||||
var DefaultNamespace = "namespace"
|
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) {
|
func New(key Type, params ...string) (db DB, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if i := recover(); i != nil {
|
if i := recover(); i != nil {
|
||||||
|
|
@ -66,6 +22,7 @@ func New(key Type, params ...string) (db DB, err error) {
|
||||||
switch key {
|
switch key {
|
||||||
case MAP:
|
case MAP:
|
||||||
db = NewMap()
|
db = NewMap()
|
||||||
|
err = nil
|
||||||
case BOLT:
|
case BOLT:
|
||||||
db, err = NewBolt(params[0])
|
db, err = NewBolt(params[0])
|
||||||
case CACHE:
|
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