store

package
v4.0.12 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package store is an interface for distributed data storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a key doesn't exist
	ErrNotFound = errors.New("not found")
	// ErrInvalidKey is returned when a key has empty or have invalid format
	ErrInvalidKey = errors.New("invalid key")
	// DefaultStore is the global default store
	DefaultStore = NewStore()
	// DefaultSeparator is the gloabal default key parts separator
	DefaultSeparator = "/"
)

Functions

func ListLimit

func ListLimit(n uint) options.Option

ListLimit limits the number of returned keys

func ListOffset

func ListOffset(n uint) options.Option

ListOffset use with Limit for pagination

func ListPrefix

func ListPrefix(s string) options.Option

ListPrefix returns all keys that are prefixed with key

func ListSuffix

func ListSuffix(s string) options.Option

ListSuffix returns all keys that end with key

func NewContext

func NewContext(ctx context.Context, c Store) context.Context

NewContext put store in context

func Separator

func Separator(s string) options.Option

Separator the value used as key parts separator

func Timeout

func Timeout(td time.Duration) options.Option

Timeout sets the timeout

func WriteMetadata

func WriteMetadata(md metadata.Metadata) options.Option

WriteMetadata add metadata.Metadata

func WriteTTL

func WriteTTL(td time.Duration) options.Option

WriteTTL is the time the record expires

Types

type DeleteOptions

type DeleteOptions struct {
	// Context holds external options
	Context context.Context
	// Namespace holds namespace
	Namespace string
}

DeleteOptions configures an individual Delete operation

func NewDeleteOptions

func NewDeleteOptions(opts ...options.Option) DeleteOptions

NewDeleteOptions fills DeleteOptions struct with opts slice

type ExistsOptions

type ExistsOptions struct {
	// Context holds external options
	Context context.Context
	// Namespace contains namespace
	Namespace string
}

ExistsOptions holds options for Exists method

func NewExistsOptions

func NewExistsOptions(opts ...options.Option) ExistsOptions

NewExistsOptions helper for Exists method

type ListOptions

type ListOptions struct {
	Context   context.Context
	Prefix    string
	Suffix    string
	Namespace string
	Limit     uint
	Offset    uint
}

ListOptions configures an individual List operation

func NewListOptions

func NewListOptions(opts ...options.Option) ListOptions

NewListOptions fills ListOptions struct with opts slice

type NamespaceStore

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

NamespaceStore wrap store with namespace

func (*NamespaceStore) Connect

func (w *NamespaceStore) Connect(ctx context.Context) error

func (*NamespaceStore) Delete

func (w *NamespaceStore) Delete(ctx context.Context, key string, opts ...options.Option) error

func (*NamespaceStore) Disconnect

func (w *NamespaceStore) Disconnect(ctx context.Context) error

func (*NamespaceStore) Exists

func (w *NamespaceStore) Exists(ctx context.Context, key string, opts ...options.Option) error

func (*NamespaceStore) Init

func (w *NamespaceStore) Init(opts ...options.Option) error

func (*NamespaceStore) List

func (w *NamespaceStore) List(ctx context.Context, opts ...options.Option) ([]string, error)

func (*NamespaceStore) Name

func (w *NamespaceStore) Name() string

func (*NamespaceStore) Options

func (w *NamespaceStore) Options() Options

func (*NamespaceStore) Read

func (w *NamespaceStore) Read(ctx context.Context, key string, val interface{}, opts ...options.Option) error

func (*NamespaceStore) String

func (w *NamespaceStore) String() string

func (*NamespaceStore) Write

func (w *NamespaceStore) Write(ctx context.Context, key string, val interface{}, opts ...options.Option) error

type Options

type Options struct {
	// Meter used for metrics
	Meter meter.Meter
	// Tracer used for tracing
	Tracer tracer.Tracer
	// Context holds external options
	Context context.Context
	// Codec used to marshal/unmarshal
	Codec codec.Codec
	// Logger used for logging
	Logger logger.Logger
	// TLSConfig holds tls.TLSConfig options
	TLSConfig *tls.Config
	// Name specifies store name
	Name string
	// Namespace of the records
	Namespace string
	// Separator used as key parts separator
	Separator string
	// Address contains store address
	Address []string
	// Timeout specifies timeout duration for all operations
	Timeout time.Duration
}

Options contains configuration for the Store

func NewOptions

func NewOptions(opts ...options.Option) Options

NewOptions creates options struct

type ReadOptions

type ReadOptions struct {
	// Context holds external options
	Context context.Context
	// Namespace holds namespace
	Namespace string
}

ReadOptions configures an individual Read operation

func NewReadOptions

func NewReadOptions(opts ...options.Option) ReadOptions

NewReadOptions fills ReadOptions struct with opts slice

type Store

type Store interface {
	Name() string
	// Init initialises the store
	Init(opts ...options.Option) error
	// Connect is used when store needs to be connected
	Connect(ctx context.Context) error
	// Options allows you to view the current options.
	Options() Options
	// Exists check that key exists in store
	Exists(ctx context.Context, key string, opts ...options.Option) error
	// Read reads a single key name to provided value with optional options
	Read(ctx context.Context, key string, val interface{}, opts ...options.Option) error
	// Write writes a value to key name to the store with optional options
	Write(ctx context.Context, key string, val interface{}, opts ...options.Option) error
	// Delete removes the record with the corresponding key from the store with optional options
	Delete(ctx context.Context, key string, opts ...options.Option) error
	// List returns any keys that match, or an empty list with no error if none matched with optional options
	List(ctx context.Context, opts ...options.Option) ([]string, error)
	// Disconnect the store
	Disconnect(ctx context.Context) error
	// String returns the name of the implementation.
	String() string
}

Store is a data storage interface

func FromContext

func FromContext(ctx context.Context) (Store, bool)

FromContext get store from context

func NewNamespaceStore

func NewNamespaceStore(s Store, ns string) Store

func NewStore

func NewStore(opts ...options.Option) Store

NewStore returns a memory store

type WriteOptions

type WriteOptions struct {
	// Context holds external options
	Context context.Context
	// Metadata contains additional metadata
	Metadata metadata.Metadata
	// Namespace holds namespace
	Namespace string
	// TTL specifies key TTL
	TTL time.Duration
}

WriteOptions configures an individual Write operation

func NewWriteOptions

func NewWriteOptions(opts ...options.Option) WriteOptions

NewWriteOptions fills WriteOptions struct with opts slice

Jump to

Keyboard shortcuts

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