kvstore

package
v1.5.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2019 License: Apache-2.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("key not found")
)

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Save saves data to the specified path
	Save(ctx context.Context, r io.Reader, path string) error
	// Load loads data from the specified path
	Load(ctx context.Context, path string) (io.ReadCloser, error)
}

func NewDatastoreBackend

func NewDatastoreBackend(ds *datastore.Helper) Backend

type KeyValueStore

type KeyValueStore interface {
	// Set adds a new key or modifies an existing key in the key-value store
	Put(ctx context.Context, key string, value []byte) error

	// Get gets an existing key in the key-value store. Returns ErrKeyNotFound
	// if key does not exist the key-value store.
	Get(key string) ([]byte, error)

	// List lists the key-value pairs whose keys match the regular expression
	// passed in.
	List(re string) (map[string][]byte, error)

	// Delete deletes existing keys from the key-value store. Returns ErrKeyNotFound
	// if key does not exist the key-value store.
	Delete(ctx context.Context, key string) error

	// Save saves the key-value store data to the backend.
	Save(ctx context.Context) error

	// Name returns the unique identifier/name for the key-value store. This is
	// used to determine the path that is passed to the backend operations.
	Name() string
}

func NewKeyValueStore

func NewKeyValueStore(ctx context.Context, store Backend, name string) (KeyValueStore, error)

Create a new KeyValueStore instance using the given Backend with the given file. If the file exists on the Backend, it is restored.

type MockBackend

type MockBackend struct {
	// contains filtered or unexported fields
}

func (*MockBackend) Load

func (m *MockBackend) Load(ctx context.Context, pth string) (io.ReadCloser, error)

func (*MockBackend) Save

func (m *MockBackend) Save(ctx context.Context, r io.Reader, pth string) error

Creates path and ovewrites whatever is there

type MockKeyValueStore

type MockKeyValueStore struct {
	mock.Mock
}

MockKeyValueStore is an autogenerated mock type for the KeyValueStore type

func (*MockKeyValueStore) Delete

func (_m *MockKeyValueStore) Delete(ctx context.Context, key string) error

Delete provides a mock function with given fields: ctx, key

func (*MockKeyValueStore) Get

func (_m *MockKeyValueStore) Get(key string) ([]byte, error)

Get provides a mock function with given fields: key

func (*MockKeyValueStore) List

func (_m *MockKeyValueStore) List(re string) (map[string][]byte, error)

List provides a mock function with given fields: re

func (*MockKeyValueStore) Name

func (_m *MockKeyValueStore) Name() string

Name provides a mock function with given fields:

func (*MockKeyValueStore) Put

func (_m *MockKeyValueStore) Put(ctx context.Context, key string, value []byte) error

Set provides a mock function with given fields: ctx, key, value

func (*MockKeyValueStore) Save

func (_m *MockKeyValueStore) Save(ctx context.Context) error

Save provides a mock function with given fields: ctx

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL