mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 11:57:44 +08:00
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
|
|
fsds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/fs"
|
|
lds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/leveldb"
|
|
syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/sync"
|
|
config "github.com/jbenet/go-ipfs/config"
|
|
)
|
|
|
|
func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, 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 syncds.MutexWrap(ds.NewMapDatastore()), nil
|
|
|
|
case "fs":
|
|
log.Warning("using fs.Datastore at .datastore for testing.")
|
|
d, err := fsds.NewDatastore(".datastore") // for testing!!
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return syncds.MutexWrap(d), nil
|
|
}
|
|
|
|
return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
|
|
}
|
|
|
|
func makeLevelDBDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
|
|
if len(cfg.Path) == 0 {
|
|
return nil, fmt.Errorf("config datastore.path required for leveldb")
|
|
}
|
|
|
|
return lds.NewDatastore(cfg.Path, nil)
|
|
}
|