storage

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package storage contains the interface for storing and retrieving data about the state of the mesh.

Index

Constants

This section is empty.

Variables

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

ErrKeyNotFound is the error returned when a key is not found.

Functions

This section is empty.

Types

type Options

type Options struct {
	// InMemory specifies whether to use an in-memory storage.
	InMemory bool
	// DiskPath is the path to the disk storage.
	DiskPath string
	// Silent specifies whether to suppress log output.
	Silent bool
}

Options are the options for creating a new Storage.

type PrefixIterator

type PrefixIterator func(key, value string) error

PrefixIterator is the function signature for iterating over all keys with a given prefix.

type Storage

type Storage interface {
	// Get returns the value of a key.
	Get(ctx context.Context, key string) (string, error)
	// Put sets the value of a key.
	Put(ctx context.Context, key, value string) error
	// Delete removes a key.
	Delete(ctx context.Context, key string) error
	// List returns all keys with a given prefix.
	List(ctx context.Context, prefix string) ([]string, error)
	// IterPrefix iterates over all keys with a given prefix. It is important
	// that the iterator not attempt any write operations as this will cause
	// a deadlock.
	IterPrefix(ctx context.Context, prefix string, fn PrefixIterator) error
	// Snapshot returns a snapshot of the storage.
	Snapshot(ctx context.Context) (io.Reader, error)
	// Restore restores a snapshot of the storage.
	Restore(ctx context.Context, r io.Reader) error
	// Subscribe will call the given function whenever a key with the given prefix is changed.
	// The returned function can be called to unsubscribe.
	Subscribe(ctx context.Context, prefix string, fn SubscribeFunc) (func(), error)
	// Close closes the storage.
	Close() error
}

Storage is the interface for storing and retrieving data about the state of the mesh.

func New

func New(opts *Options) (Storage, error)

New returns a new Storage.

func NewTestStorage

func NewTestStorage() (Storage, error)

NewTestStorage is a helper for creating an in-memory storage suitable for testing.

type SubscribeFunc

type SubscribeFunc func(key, value string)

SubscribeFunc is the function signature for subscribing to changes to a key.

Jump to

Keyboard shortcuts

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