Commit 7b9cfda0 authored by Jeromy's avatar Jeromy Committed by Łukasz Magiera

add support for datastore plugins

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent 238bd012
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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment