2021-07-14 17:11:37 +03:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// LogfFunc function used for Logf method
|
2021-09-28 23:43:43 +03:00
|
|
|
// type LogfFunc func(ctx context.Context, level Level, msg string, args ...interface{})
|
|
|
|
// type Wrapper interface {
|
|
|
|
// Logf logs message with needed level
|
|
|
|
// Logf(LogfFunc) LogfFunc
|
|
|
|
// }
|
2021-07-14 17:11:37 +03:00
|
|
|
|
2021-09-28 23:43:43 +03:00
|
|
|
// NamespaceStore wrap store with namespace
|
2021-07-14 17:11:37 +03:00
|
|
|
type NamespaceStore struct {
|
|
|
|
s Store
|
|
|
|
ns string
|
|
|
|
}
|
|
|
|
|
2021-09-28 23:43:43 +03:00
|
|
|
var _ Store = &NamespaceStore{}
|
2021-07-14 17:11:37 +03:00
|
|
|
|
|
|
|
func NewNamespaceStore(s Store, ns string) Store {
|
|
|
|
return &NamespaceStore{s: s, ns: ns}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Init(opts ...Option) error {
|
|
|
|
return w.s.Init(opts...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Connect(ctx context.Context) error {
|
|
|
|
return w.s.Connect(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Disconnect(ctx context.Context) error {
|
|
|
|
return w.s.Disconnect(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Read(ctx context.Context, key string, val interface{}, opts ...ReadOption) error {
|
|
|
|
return w.s.Read(ctx, key, val, append(opts, ReadNamespace(w.ns))...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Write(ctx context.Context, key string, val interface{}, opts ...WriteOption) error {
|
|
|
|
return w.s.Write(ctx, key, val, append(opts, WriteNamespace(w.ns))...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Delete(ctx context.Context, key string, opts ...DeleteOption) error {
|
|
|
|
return w.s.Delete(ctx, key, append(opts, DeleteNamespace(w.ns))...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Exists(ctx context.Context, key string, opts ...ExistsOption) error {
|
|
|
|
return w.s.Exists(ctx, key, append(opts, ExistsNamespace(w.ns))...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) List(ctx context.Context, opts ...ListOption) ([]string, error) {
|
|
|
|
return w.s.List(ctx, append(opts, ListNamespace(w.ns))...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Options() Options {
|
|
|
|
return w.s.Options()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) Name() string {
|
|
|
|
return w.s.Name()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *NamespaceStore) String() string {
|
|
|
|
return w.s.String()
|
|
|
|
}
|
|
|
|
|
2021-09-28 23:43:43 +03:00
|
|
|
// type NamespaceWrapper struct{}
|
2021-07-14 17:11:37 +03:00
|
|
|
|
2021-09-30 01:24:16 +03:00
|
|
|
// func NewNamespaceWrapper() Wrapper {
|
2021-07-14 17:11:37 +03:00
|
|
|
// return &NamespaceWrapper{}
|
2021-09-30 01:24:16 +03:00
|
|
|
// }
|
2021-07-14 17:11:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
func (w *OmitWrapper) Logf(fn LogfFunc) LogfFunc {
|
|
|
|
return func(ctx context.Context, level Level, msg string, args ...interface{}) {
|
|
|
|
fn(ctx, level, msg, getArgs(args)...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|