libnetwork/kvstore: rewrite code for new location
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
3887475971
commit
5d25143ef3
3 changed files with 13 additions and 16 deletions
|
@ -10,8 +10,7 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/docker/libkv"
|
||||
"github.com/docker/libkv/store"
|
||||
store "github.com/docker/docker/libnetwork/internal/kvstore"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
|
@ -27,7 +26,7 @@ const (
|
|||
filePerm os.FileMode = 0644
|
||||
)
|
||||
|
||||
//BoltDB type implements the Store interface
|
||||
// BoltDB type implements the Store interface
|
||||
type BoltDB struct {
|
||||
client *bolt.DB
|
||||
boltBucket []byte
|
||||
|
@ -50,7 +49,7 @@ const (
|
|||
|
||||
// Register registers boltdb to libkv
|
||||
func Register() {
|
||||
libkv.AddStore(store.BOLTDB, New)
|
||||
store.AddStore(store.BOLTDB, New)
|
||||
}
|
||||
|
||||
// New opens a new BoltDB connection to the specified path and bucket
|
||||
|
@ -167,7 +166,7 @@ func (b *BoltDB) Get(key string) (*store.KVPair, error) {
|
|||
return &store.KVPair{Key: key, Value: val, LastIndex: (dbIndex)}, nil
|
||||
}
|
||||
|
||||
//Put the key, value pair. index number metadata is prepended to the value
|
||||
// Put the key, value pair. index number metadata is prepended to the value
|
||||
func (b *BoltDB) Put(key string, value []byte, opts *store.WriteOptions) error {
|
||||
var (
|
||||
dbIndex uint64
|
||||
|
@ -203,7 +202,7 @@ func (b *BoltDB) Put(key string, value []byte, opts *store.WriteOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
//Delete the value for the given key.
|
||||
// Delete the value for the given key.
|
||||
func (b *BoltDB) Delete(key string) error {
|
||||
var (
|
||||
db *bolt.DB
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package store
|
||||
package kvstore
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
package libkv
|
||||
package kvstore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/libkv/store"
|
||||
)
|
||||
|
||||
// Initialize creates a new Store object, initializing the client
|
||||
type Initialize func(addrs []string, options *store.Config) (store.Store, error)
|
||||
type Initialize func(addrs []string, options *Config) (Store, error)
|
||||
|
||||
var (
|
||||
// Backend initializers
|
||||
initializers = make(map[store.Backend]Initialize)
|
||||
initializers = make(map[Backend]Initialize)
|
||||
|
||||
supportedBackend = func() string {
|
||||
keys := make([]string, 0, len(initializers))
|
||||
|
@ -25,16 +23,16 @@ var (
|
|||
}()
|
||||
)
|
||||
|
||||
// NewStore creates an instance of store
|
||||
func NewStore(backend store.Backend, addrs []string, options *store.Config) (store.Store, error) {
|
||||
// New creates an instance of store
|
||||
func New(backend Backend, addrs []string, options *Config) (Store, error) {
|
||||
if init, exists := initializers[backend]; exists {
|
||||
return init(addrs, options)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s %s", store.ErrBackendNotSupported.Error(), supportedBackend)
|
||||
return nil, fmt.Errorf("%s %s", ErrBackendNotSupported.Error(), supportedBackend)
|
||||
}
|
||||
|
||||
// AddStore adds a new store backend to libkv
|
||||
func AddStore(store store.Backend, init Initialize) {
|
||||
func AddStore(store Backend, init Initialize) {
|
||||
initializers[store] = init
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue