kv

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSectionNotFound = errors.New("database not found in the config")
	ErrDriverNotFound  = errors.New("database driver not found")
)

Functions

func Register

func Register(name string, driver Driver)

Register stores the association of the name with the Driver implementation internally. This function must be called for each Driver.

Types

type Deleter

type Deleter interface {
	KeyValue
	Delete(key string) error
}

Deleter defines an extension interface for KeyValue implementations that defines the Delete operation on the Database.

This interface is used in the "del" command.

type Driver

type Driver interface {
	New() KeyValue
}

Driver defines an interface for initializing new KeyValue implementation. The databases will have corresponding Driver implementations.

To use a Driver with this package, it must first be registered through the Register function.

type DriverFunc

type DriverFunc func() KeyValue

DriverFunc defines a function type that implements the Driver interface.

func (DriverFunc) New

func (df DriverFunc) New() KeyValue

type Event

type Event struct {
	Key   string
	Value []byte
}

Event defines the struct used for Watcher to receive Events from the Driver.

type Initializer

type Initializer interface {
	Init() error
}

Initializer defines the interface that a KeyValue implementation can implement if explicit initialization is required.

This method will be called after the configuration is marshalled into the implementation struct.

type Iterator

type Iterator interface {
	io.Closer
	Next() (string, []byte, bool)
}

Iterator defines the interface for iterating over the key-values of the Database.

type KeyValue

type KeyValue interface {
	Get(key string) ([]byte, error)
	Set(key string, value []byte) error
}

KeyValue is the most basic interface that each Database MUST implement.

func Open

func Open(s config.Section) (KeyValue, io.Closer, error)

Open opens a new database connection based on the configuration specified in the Section.

The Section must specify a Driver that is registered in this package to successfully open the connection.

type Lister

type Lister interface {
	KeyValue
	List(prefix string) (Iterator, error)
}

Lister defines an extension inteface for KeyValue implementations that can list the keys in the Database.

type Searcher

type Searcher interface {
	KeyValue
	Search(term string) (Iterator, error)
}

Searcher defines an extension inteface for KeyValue implementations that can search for keys in the Database.

type Watcher

type Watcher interface {
	KeyValue
	Watch(ctx context.Context, key string) <-chan Event
}

Watcher defines an extension interface for KeyValue implementations that can watch for changes in Keys.

This interface is used in the "watch" command.

Jump to

Keyboard shortcuts

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