Documentation ¶
Overview ¶
Package store is an interface for distributed data storage.
Index ¶
- Variables
- func NewContext(ctx context.Context, c Store) context.Context
- func NewStore(opts ...Option) *noopStore
- type DeleteOption
- type DeleteOptions
- type ExistsOption
- type ExistsOptions
- type FuncDelete
- type FuncExists
- type FuncList
- type FuncRead
- type FuncWrite
- type HookDelete
- type HookExists
- type HookList
- type HookRead
- type HookWrite
- type ListOption
- func ListContext(ctx context.Context) ListOption
- func ListLimit(n uint) ListOption
- func ListNamespace(ns string) ListOption
- func ListOffset(n uint) ListOption
- func ListPrefix(s string) ListOption
- func ListSuffix(s string) ListOption
- func ListTimeout(td time.Duration) ListOption
- func SetListOption(k, v interface{}) ListOption
- type ListOptions
- type NamespaceStore
- func (w *NamespaceStore) Connect(ctx context.Context) error
- func (w *NamespaceStore) Delete(ctx context.Context, key string, opts ...DeleteOption) error
- func (w *NamespaceStore) Disconnect(ctx context.Context) error
- func (w *NamespaceStore) Exists(ctx context.Context, key string, opts ...ExistsOption) error
- func (w *NamespaceStore) Init(opts ...Option) error
- func (w *NamespaceStore) List(ctx context.Context, opts ...ListOption) ([]string, error)
- func (w *NamespaceStore) Name() string
- func (w *NamespaceStore) Options() Options
- func (w *NamespaceStore) Read(ctx context.Context, key string, val interface{}, opts ...ReadOption) error
- func (w *NamespaceStore) String() string
- func (w *NamespaceStore) Write(ctx context.Context, key string, val interface{}, opts ...WriteOption) error
- type Option
- func Addrs(addrs ...string) Option
- func Codec(c codec.Codec) Option
- func Context(ctx context.Context) Option
- func Hooks(h ...options.Hook) Option
- func Logger(l logger.Logger) Option
- func Meter(m meter.Meter) Option
- func Name(n string) Option
- func Namespace(ns string) Option
- func Separator(s string) Option
- func SetOption(k, v interface{}) Option
- func TLSConfig(t *tls.Config) Option
- func Timeout(td time.Duration) Option
- func Tracer(t tracer.Tracer) Option
- type Options
- type ReadOption
- type ReadOptions
- type Store
- type WriteOption
- func SetWriteOption(k, v interface{}) WriteOption
- func WriteContext(ctx context.Context) WriteOption
- func WriteMetadata(md metadata.Metadata) WriteOption
- func WriteName(name string) WriteOption
- func WriteNamespace(ns string) WriteOption
- func WriteTTL(d time.Duration) WriteOption
- func WriteTimeout(td time.Duration) WriteOption
- 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 Store = NewStore() // DefaultSeparator is the gloabal default key parts separator DefaultSeparator = "/" )
Functions ¶
func NewContext ¶
NewContext put store in context
Types ¶
type DeleteOption ¶
type DeleteOption func(d *DeleteOptions)
DeleteOption sets values in DeleteOptions
func DeleteContext ¶
func DeleteContext(ctx context.Context) DeleteOption
DeleteContext pass context.Context to delete options
func DeleteName ¶ added in v3.10.60
func DeleteName(name string) DeleteOption
DeleteName pass name to DeleteOptions
func DeleteNamespace ¶
func DeleteNamespace(ns string) DeleteOption
DeleteNamespace pass namespace to delete options
func DeleteTimeout ¶ added in v3.10.60
func DeleteTimeout(td time.Duration) DeleteOption
DeleteTimeout pass timeout to DeleteOptions
func SetDeleteOption ¶
func SetDeleteOption(k, v interface{}) DeleteOption
SetDeleteOption returns a function to setup a context with given value
type DeleteOptions ¶
type DeleteOptions struct { // Context holds external options Context context.Context // Namespace holds namespace Namespace string // Name holds mnemonic name Name string // Timeout specifies max timeout for operation Timeout time.Duration }
DeleteOptions configures an individual Delete operation
func NewDeleteOptions ¶
func NewDeleteOptions(opts ...DeleteOption) DeleteOptions
NewDeleteOptions fills DeleteOptions struct with opts slice
type ExistsOption ¶
type ExistsOption func(*ExistsOptions)
ExistsOption specifies Exists call options
func ExistsContext ¶
func ExistsContext(ctx context.Context) ExistsOption
ExistsContext pass context.Context to exist options
func ExistsName ¶ added in v3.10.60
func ExistsName(name string) ExistsOption
ExistsName pass name to exist options
func ExistsNamespace ¶
func ExistsNamespace(ns string) ExistsOption
ExistsNamespace pass namespace to exist options
func ExistsTimeout ¶ added in v3.10.60
func ExistsTimeout(td time.Duration) ExistsOption
ExistsTimeout timeout to ListOptions
func SetExistsOption ¶
func SetExistsOption(k, v interface{}) ExistsOption
SetExistsOption returns a function to setup a context with given value
type ExistsOptions ¶
type ExistsOptions struct { // Context holds external options Context context.Context // Namespace contains namespace Namespace string // Name holds mnemonic name Name string // Timeout specifies max timeout for operation Timeout time.Duration }
ExistsOptions holds options for Exists method
func NewExistsOptions ¶
func NewExistsOptions(opts ...ExistsOption) ExistsOptions
NewExistsOptions helper for Exists method
type FuncDelete ¶ added in v3.10.63
type FuncDelete func(ctx context.Context, key string, opts ...DeleteOption) error
type FuncExists ¶ added in v3.10.63
type FuncExists func(ctx context.Context, key string, opts ...ExistsOption) error
type FuncList ¶ added in v3.10.63
type FuncList func(ctx context.Context, opts ...ListOption) ([]string, error)
type FuncRead ¶ added in v3.10.63
type FuncRead func(ctx context.Context, key string, val interface{}, opts ...ReadOption) error
type FuncWrite ¶ added in v3.10.63
type FuncWrite func(ctx context.Context, key string, val interface{}, opts ...WriteOption) error
type HookDelete ¶ added in v3.10.63
type HookDelete func(next FuncDelete) FuncDelete
type HookExists ¶ added in v3.10.63
type HookExists func(next FuncExists) FuncExists
type ListOption ¶
type ListOption func(l *ListOptions)
ListOption sets values in ListOptions
func ListContext ¶
func ListContext(ctx context.Context) ListOption
ListContext pass context.Context to list options
func ListNamespace ¶
func ListNamespace(ns string) ListOption
ListNamespace pass namespace to list options
func ListPrefix ¶
func ListPrefix(s string) ListOption
ListPrefix returns all keys that are prefixed with key
func ListSuffix ¶
func ListSuffix(s string) ListOption
ListSuffix returns all keys that end with key
func ListTimeout ¶ added in v3.10.60
func ListTimeout(td time.Duration) ListOption
ListTimeout pass timeout to ListOptions
func SetListOption ¶
func SetListOption(k, v interface{}) ListOption
SetListOption returns a function to setup a context with given value
type ListOptions ¶
type ListOptions struct { Context context.Context Prefix string Suffix string Namespace string // Name holds mnemonic name Name string Limit uint Offset uint // Timeout specifies max timeout for operation Timeout time.Duration }
ListOptions configures an individual List operation
func NewListOptions ¶
func NewListOptions(opts ...ListOption) 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) Delete ¶
func (w *NamespaceStore) Delete(ctx context.Context, key string, opts ...DeleteOption) 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 ...ExistsOption) error
func (*NamespaceStore) Init ¶
func (w *NamespaceStore) Init(opts ...Option) error
func (*NamespaceStore) List ¶
func (w *NamespaceStore) List(ctx context.Context, opts ...ListOption) ([]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 ...ReadOption) error
func (*NamespaceStore) String ¶
func (w *NamespaceStore) String() string
func (*NamespaceStore) Write ¶
func (w *NamespaceStore) Write(ctx context.Context, key string, val interface{}, opts ...WriteOption) error
type Option ¶
type Option func(o *Options)
Option sets values in Options
func Addrs ¶
Addrs contains the addresses or other connection information of the backing storage. For example, an etcd implementation would contain the nodes of the cluster. A SQL implementation could contain one or more connection strings.
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 // Addrs contains store address Addrs []string // Wrappers store wrapper that called before actual functions // Wrappers []Wrapper // Timeout specifies timeout duration for all operations Timeout time.Duration // Hooks can be run before/after store Read/List/Write/Exists/Delete Hooks options.Hooks }
Options contains configuration for the Store
type ReadOption ¶
type ReadOption func(r *ReadOptions)
ReadOption sets values in ReadOptions
func ReadContext ¶
func ReadContext(ctx context.Context) ReadOption
ReadContext pass context.Context to ReadOptions
func ReadName ¶ added in v3.10.60
func ReadName(name string) ReadOption
ReadName pass name to ReadOptions
func ReadNamespace ¶
func ReadNamespace(ns string) ReadOption
ReadNamespace pass namespace to ReadOptions
func ReadTimeout ¶ added in v3.10.60
func ReadTimeout(td time.Duration) ReadOption
ReadTimeout pass timeout to ReadOptions
func SetReadOption ¶
func SetReadOption(k, v interface{}) ReadOption
SetReadOption returns a function to setup a context with given value
type ReadOptions ¶
type ReadOptions struct { // Context holds external options Context context.Context // Namespace holds namespace Namespace string // Name holds mnemonic name Name string // Timeout specifies max timeout for operation Timeout time.Duration }
ReadOptions configures an individual Read operation
func NewReadOptions ¶
func NewReadOptions(opts ...ReadOption) ReadOptions
NewReadOptions fills ReadOptions struct with opts slice
type Store ¶
type Store interface { // Name returns store name Name() string // Init initialises the store Init(opts ...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 ...ExistsOption) error // Read reads a single key name to provided value with optional ReadOptions Read(ctx context.Context, key string, val interface{}, opts ...ReadOption) error // Write writes a value to key name to the store with optional WriteOption Write(ctx context.Context, key string, val interface{}, opts ...WriteOption) error // Delete removes the record with the corresponding key from the store. Delete(ctx context.Context, key string, opts ...DeleteOption) error // List returns any keys that match, or an empty list with no error if none matched. List(ctx context.Context, opts ...ListOption) ([]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 WriteOption ¶
type WriteOption func(w *WriteOptions)
WriteOption sets values in WriteOptions
func SetWriteOption ¶
func SetWriteOption(k, v interface{}) WriteOption
SetWriteOption returns a function to setup a context with given value
func WriteContext ¶
func WriteContext(ctx context.Context) WriteOption
WriteContext pass context.Context to wirte options
func WriteMetadata ¶
func WriteMetadata(md metadata.Metadata) WriteOption
WriteMetadata add metadata.Metadata
func WriteName ¶ added in v3.10.60
func WriteName(name string) WriteOption
WriteName pass name to WriteOptions
func WriteNamespace ¶
func WriteNamespace(ns string) WriteOption
WriteNamespace pass namespace to write options
func WriteTimeout ¶ added in v3.10.60
func WriteTimeout(td time.Duration) WriteOption
WriteTimeout pass timeout to WriteOptions
type WriteOptions ¶
type WriteOptions struct { // Context holds external options Context context.Context // Metadata contains additional metadata Metadata metadata.Metadata // Namespace holds namespace Namespace string // Name holds mnemonic name Name string // Timeout specifies max timeout for operation Timeout time.Duration // TTL specifies key TTL TTL time.Duration }
WriteOptions configures an individual Write operation
func NewWriteOptions ¶
func NewWriteOptions(opts ...WriteOption) WriteOptions
NewWriteOptions fills WriteOptions struct with opts slice