mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
add support for datastore plugins
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
parent
238bd01224
commit
7b9cfda084
14
plugin/datastore.go
Normal file
14
plugin/datastore.go
Normal file
@ -0,0 +1,14 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
)
|
||||
|
||||
// PluginDatastore is an interface that can be implemented to add handlers for
|
||||
// for different datastores
|
||||
type PluginDatastore interface {
|
||||
Plugin
|
||||
|
||||
DatastoreTypeName() string
|
||||
DatastoreConfigParser() fsrepo.ConfigFromMap
|
||||
}
|
||||
@ -3,8 +3,9 @@ package loader
|
||||
import (
|
||||
"github.com/ipfs/go-ipfs/core/coredag"
|
||||
"github.com/ipfs/go-ipfs/plugin"
|
||||
"gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"
|
||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
"gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"
|
||||
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
||||
)
|
||||
|
||||
@ -32,6 +33,11 @@ func run(plugins []plugin.Plugin) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case plugin.PluginDatastore:
|
||||
err := fsrepo.AddDatastoreConfigHandler(pl.DatastoreTypeName(), pl.DatastoreConfigParser())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
panic(pl)
|
||||
}
|
||||
|
||||
@ -36,7 +36,12 @@ type DatastoreConfig interface {
|
||||
Create(path string) (repo.Datastore, error)
|
||||
}
|
||||
|
||||
// DiskSpec is the type returned by the DatastoreConfig's DiskSpec method
|
||||
// DiskSpec is a minimal representation of the characteristic values of the
|
||||
// datastore. If two diskspecs are the same, the loader assumes that they refer
|
||||
// to exactly the same datastore. If they differ at all, it is assumed they are
|
||||
// completely different datastores and a migration will be performed. Runtime
|
||||
// values such as cache options or concurrency options should not be added
|
||||
// here.
|
||||
type DiskSpec map[string]interface{}
|
||||
|
||||
// Bytes returns a minimal JSON encoding of the DiskSpec
|
||||
@ -68,6 +73,16 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func AddDatastoreConfigHandler(name string, dsc ConfigFromMap) error {
|
||||
_, ok := datastores[name]
|
||||
if ok {
|
||||
return fmt.Errorf("already have a datastore named %q", name)
|
||||
}
|
||||
|
||||
datastores[name] = dsc
|
||||
return nil
|
||||
}
|
||||
|
||||
// AnyDatastoreConfig returns a DatastoreConfig from a spec based on
|
||||
// the "type" parameter
|
||||
func AnyDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user