store

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: CC0-1.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when the store implementation cannot find the value
	// for a given key.
	ErrNotFound = errors.New("store: key not found")

	// ErrCantDecode is returned when a store adaptor cannot decode the store format
	// to a value used by the code.
	ErrCantDecode = errors.New("store: can't decode value")

	// ErrCantEncode is returned when a store adaptor cannot encode the value into
	// the format that the store uses.
	ErrCantEncode = errors.New("store: can't encode value")

	// ErrBadConfig is returned when a store adaptor's configuration is invalid.
	ErrBadConfig = errors.New("store: configuration is invalid")
)

Functions

func Close

func Close(s Interface) error

Close closes the store if it implements Closer, otherwise returns nil.

Types

type CAS

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

func (*CAS) Close

func (c *CAS) Close() error

func (*CAS) Delete

func (c *CAS) Delete(ctx context.Context, key string) error

func (*CAS) Exists

func (c *CAS) Exists(ctx context.Context, key string) error

func (*CAS) Get

func (c *CAS) Get(ctx context.Context, key string) ([]byte, error)

func (*CAS) List

func (c *CAS) List(ctx context.Context, prefix string) ([]string, error)

func (*CAS) Set

func (c *CAS) Set(ctx context.Context, key string, value []byte) error

type Closer

type Closer interface {
	Close() error
}

Closer is an optional interface for stores that need explicit cleanup. Use Close() to safely close a store, which will call Close() on the underlying store if it implements Closer, otherwise it does nothing.

type DirectFile

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

func (*DirectFile) Delete

func (d *DirectFile) Delete(ctx context.Context, key string) error

func (*DirectFile) Exists

func (d *DirectFile) Exists(ctx context.Context, key string) error

func (*DirectFile) Get

func (d *DirectFile) Get(ctx context.Context, key string) ([]byte, error)

func (*DirectFile) List

func (d *DirectFile) List(ctx context.Context, prefix string) ([]string, error)

func (*DirectFile) Set

func (d *DirectFile) Set(ctx context.Context, key string, value []byte) error

type Interface

type Interface interface {
	// Delete removes a value from the store by key.
	Delete(ctx context.Context, key string) error

	// Exists returns nil if the key exists, ErrNotFound if it does not exist.
	Exists(ctx context.Context, key string) error

	// Get returns the value of a key assuming that value exists and has not expired.
	Get(ctx context.Context, key string) ([]byte, error)

	// Set puts a value into the store that expires according to its expiry.
	Set(ctx context.Context, key string, value []byte) error

	// List lists the keys in this keyspace optionally matching by a prefix.
	List(ctx context.Context, prefix string) ([]string, error)
}

Interface defines the calls that Anubis uses for storage in a local or remote datastore. This can be implemented with an in-memory, on-disk, or in-database storage backend.

func NewCAS

func NewCAS(baseDir string) (Interface, error)

func NewDirectFile

func NewDirectFile(baseDir string) (Interface, error)

func NewJSONMutexDB

func NewJSONMutexDB(baseDir string) (Interface, error)

func NewS3API

func NewS3API(ctx context.Context, bucket string) (Interface, error)

type JSON

type JSON[T any] struct {
	Underlying Interface
	Prefix     string
}

func (*JSON[T]) Delete

func (j *JSON[T]) Delete(ctx context.Context, key string) error

func (*JSON[T]) Exists

func (j *JSON[T]) Exists(ctx context.Context, key string) error

func (*JSON[T]) Get

func (j *JSON[T]) Get(ctx context.Context, key string) (T, error)

func (*JSON[T]) List

func (j *JSON[T]) List(ctx context.Context, prefix string) ([]string, error)

func (*JSON[T]) Set

func (j *JSON[T]) Set(ctx context.Context, key string, value T) error

type JSONMutexDB

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

func (*JSONMutexDB) Close

func (j *JSONMutexDB) Close() error

func (*JSONMutexDB) Delete

func (j *JSONMutexDB) Delete(ctx context.Context, key string) error

func (*JSONMutexDB) Exists

func (j *JSONMutexDB) Exists(ctx context.Context, key string) error

func (*JSONMutexDB) Get

func (j *JSONMutexDB) Get(ctx context.Context, key string) ([]byte, error)

func (*JSONMutexDB) List

func (j *JSONMutexDB) List(ctx context.Context, prefix string) ([]string, error)

func (*JSONMutexDB) Set

func (j *JSONMutexDB) Set(ctx context.Context, key string, value []byte) error

type S3API

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

func (*S3API) Delete

func (s *S3API) Delete(ctx context.Context, key string) error

func (*S3API) Exists

func (s *S3API) Exists(ctx context.Context, key string) error

func (*S3API) Get

func (s *S3API) Get(ctx context.Context, key string) ([]byte, error)

func (*S3API) List

func (s *S3API) List(ctx context.Context, prefix string) ([]string, error)

func (*S3API) Set

func (s *S3API) Set(ctx context.Context, key string, value []byte) error

Jump to

Keyboard shortcuts

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