kubo/core/datastore.go
Brian Tiger Chow a5c0f67c8c fix(config) failing test
also replace *Datastore with Datastore
2014-09-12 04:20:46 -07:00

33 lines
816 B
Go

package core
import (
"fmt"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
lds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/leveldb"
config "github.com/jbenet/go-ipfs/config"
)
func makeDatastore(cfg config.Datastore) (ds.Datastore, error) {
if len(cfg.Type) == 0 {
return nil, fmt.Errorf("config datastore.type required")
}
switch cfg.Type {
case "leveldb":
return makeLevelDBDatastore(cfg)
case "memory":
return ds.NewMapDatastore(), nil
}
return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
}
func makeLevelDBDatastore(cfg config.Datastore) (ds.Datastore, error) {
if len(cfg.Path) == 0 {
return nil, fmt.Errorf("config datastore.path required for leveldb")
}
return lds.NewDatastore(cfg.Path, nil)
}