add support for datastore plugins
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jul 4, 2018 at 10:50 UTC
7b9cfda0841db03a1292cd0198ada14c061be2af
3 files changed
+37
-2
plugin/datastore.go
new
+14
@@ -0,0 +1,14 @@
1
+package plugin
2
+
3
+import (
4
+ "github.com/ipfs/go-ipfs/repo/fsrepo"
5
+)
6
+
7
+// PluginDatastore is an interface that can be implemented to add handlers for
8
+// for different datastores
9
+type PluginDatastore interface {
10
+ Plugin
11
+
12
+ DatastoreTypeName() string
13
+ DatastoreConfigParser() fsrepo.ConfigFromMap
14
+}
plugin/loader/initializer.go
+7
-1
@@ -3,8 +3,9 @@ package loader
3
import (
4
"github.com/ipfs/go-ipfs/core/coredag"
5
"github.com/ipfs/go-ipfs/plugin"
6
- "gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"
6
+ "github.com/ipfs/go-ipfs/repo/fsrepo"
7
8
+ "gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"
9
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
10
)
11
@@ -32,6 +33,11 @@ func run(plugins []plugin.Plugin) error {
33
if err != nil {
34
return err
35
}
36
+ case plugin.PluginDatastore:
37
+ err := fsrepo.AddDatastoreConfigHandler(pl.DatastoreTypeName(), pl.DatastoreConfigParser())
38
+ if err != nil {
39
+ return err
40
+ }
41
default:
42
panic(pl)
43
}
repo/fsrepo/datastores.go
+16
-1
@@ -36,7 +36,12 @@ type DatastoreConfig interface {
36
Create(path string) (repo.Datastore, error)
37
}
38
39
-// DiskSpec is the type returned by the DatastoreConfig's DiskSpec method
39
+// DiskSpec is a minimal representation of the characteristic values of the
40
+// datastore. If two diskspecs are the same, the loader assumes that they refer
41
+// to exactly the same datastore. If they differ at all, it is assumed they are
42
+// completely different datastores and a migration will be performed. Runtime
43
+// values such as cache options or concurrency options should not be added
44
+// here.
45
type DiskSpec map[string]interface{}
46
47
// Bytes returns a minimal JSON encoding of the DiskSpec
@@ -68,6 +73,16 @@ func init() {
73
}
74
}
75
76
+func AddDatastoreConfigHandler(name string, dsc ConfigFromMap) error {
77
+ _, ok := datastores[name]
78
+ if ok {
79
+ return fmt.Errorf("already have a datastore named %q", name)
80
+ }
81
+
82
+ datastores[name] = dsc
83
+ return nil
84
+}
85
+
86
// AnyDatastoreConfig returns a DatastoreConfig from a spec based on
87
// the "type" parameter
88
func AnyDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {