Documentation
¶
Overview ¶
Package store is an interface for distributed data storage.
Index ¶
- Variables
- func ListLimit(n uint) options.Option
- func ListOffset(n uint) options.Option
- func ListPrefix(s string) options.Option
- func ListSuffix(s string) options.Option
- func NewContext(ctx context.Context, c Store) context.Context
- func Separator(s string) options.Option
- func Timeout(td time.Duration) options.Option
- func WriteMetadata(md metadata.Metadata) options.Option
- func WriteTTL(td time.Duration) options.Option
- type DeleteOptions
- type ExistsOptions
- type ListOptions
- type NamespaceStore
- func (w *NamespaceStore) Connect(ctx context.Context) error
- func (w *NamespaceStore) Delete(ctx context.Context, key string, opts ...options.Option) error
- func (w *NamespaceStore) Disconnect(ctx context.Context) error
- func (w *NamespaceStore) Exists(ctx context.Context, key string, opts ...options.Option) error
- func (w *NamespaceStore) Init(opts ...options.Option) error
- func (w *NamespaceStore) List(ctx context.Context, opts ...options.Option) ([]string, error)
- func (w *NamespaceStore) Name() string
- func (w *NamespaceStore) Options() Options
- func (w *NamespaceStore) Read(ctx context.Context, key string, val interface{}, opts ...options.Option) error
- func (w *NamespaceStore) String() string
- func (w *NamespaceStore) Write(ctx context.Context, key string, val interface{}, opts ...options.Option) error
- type Options
- type ReadOptions
- type Store
- type WriteOptions
Constants ¶
This section is empty.
Variables ¶
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 ListPrefix ¶
ListPrefix returns all keys that are prefixed with key
func ListSuffix ¶
ListSuffix returns all keys that end with key
func NewContext ¶
NewContext put store in context
func WriteMetadata ¶
WriteMetadata add metadata.Metadata
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) Disconnect ¶
func (w *NamespaceStore) Disconnect(ctx context.Context) error
func (*NamespaceStore) Name ¶
func (w *NamespaceStore) Name() string
func (*NamespaceStore) Options ¶
func (w *NamespaceStore) Options() Options
func (*NamespaceStore) String ¶
func (w *NamespaceStore) String() string
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
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 ¶
FromContext get store from context
func NewNamespaceStore ¶
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