Browse Source

No global config

pull/1842/head
Jae Kwon 9 years ago
parent
commit
31fdd21c7e
2 changed files with 4 additions and 25 deletions
  1. +0
    -13
      config.go
  2. +4
    -12
      db.go

+ 0
- 13
config.go View File

@ -1,13 +0,0 @@
package db
import (
cfg "github.com/tendermint/go-config"
)
var config cfg.Config = nil
func init() {
cfg.OnConfig(func(newConfig cfg.Config) {
config = newConfig
})
}

+ 4
- 12
db.go View File

@ -24,27 +24,19 @@ type DB interface {
const DBBackendMemDB = "memdb"
const DBBackendLevelDB = "leveldb"
var dbs = NewCMap()
func GetDB(name string) DB {
db := dbs.Get(name)
if db != nil {
return db.(DB)
}
switch config.GetString("db_backend") {
func NewDB(name string, backend string, dir string) DB {
switch backend {
case DBBackendMemDB:
db := NewMemDB()
dbs.Set(name, db)
return db
case DBBackendLevelDB:
db, err := NewLevelDB(path.Join(config.GetString("db_dir"), name+".db"))
db, err := NewLevelDB(path.Join(dir, name+".db"))
if err != nil {
PanicCrisis(err)
}
dbs.Set(name, db)
return db
default:
PanicSanity(Fmt("Unknown DB backend: %v", config.GetString("db_backend")))
PanicSanity(Fmt("Unknown DB backend: %v", backend))
}
return nil
}

Loading…
Cancel
Save