Parcourir la source

Merge pull request #51 from abronan/fix_vendor_import

Refactor libkv to not directly import storage backends
Alexandre Beslic il y a 9 ans
Parent
commit
29a75f0428

+ 6 - 0
libnetwork/internal/kvstore/boltdb/boltdb.go

@@ -9,6 +9,7 @@ import (
 	"sync/atomic"
 
 	"github.com/boltdb/bolt"
+	"github.com/docker/libkv"
 	"github.com/docker/libkv/store"
 )
 
@@ -35,6 +36,11 @@ const (
 	libkvmetadatalen = 8
 )
 
+// Register registers boltdb to libkv
+func Register() {
+	libkv.AddStore(store.BOLTDB, New)
+}
+
 // New opens a new BoltDB connection to the specified path and bucket
 func New(endpoints []string, options *store.Config) (store.Store, error) {
 	if len(endpoints) > 1 {

+ 7 - 10
libnetwork/internal/kvstore/kvstore_manage.go

@@ -67,10 +67,6 @@ import (
 	"strings"
 
 	"github.com/docker/libkv/store"
-	"github.com/docker/libkv/store/boltdb"
-	"github.com/docker/libkv/store/consul"
-	"github.com/docker/libkv/store/etcd"
-	"github.com/docker/libkv/store/zookeeper"
 )
 
 // Initialize creates a new Store object, initializing the client
@@ -78,12 +74,8 @@ type Initialize func(addrs []string, options *store.Config) (store.Store, error)
 
 var (
 	// Backend initializers
-	initializers = map[store.Backend]Initialize{
-		store.CONSUL: consul.New,
-		store.ETCD:   etcd.New,
-		store.ZK:     zookeeper.New,
-		store.BOLTDB: boltdb.New,
-	}
+	initializers = make(map[store.Backend]Initialize)
+
 	supportedBackend = func() string {
 		keys := make([]string, 0, len(initializers))
 		for k := range initializers {
@@ -102,3 +94,8 @@ func NewStore(backend store.Backend, addrs []string, options *store.Config) (sto
 
 	return nil, fmt.Errorf("%s %s", store.ErrNotSupported.Error(), supportedBackend)
 }
+
+// AddStore adds a new store backend to libkv
+func AddStore(store store.Backend, init Initialize) {
+	initializers[store] = init
+}