2021-07-14 17:11:37 +03:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
"go.unistack.org/micro/v4/options"
|
|
|
|
)
|
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}
|
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (w *NamespaceStore) Init(opts ...options.Option) error {
|
2021-07-14 17:11:37 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (w *NamespaceStore) Read(ctx context.Context, key string, val interface{}, opts ...options.Option) error {
|
|
|
|
return w.s.Read(ctx, key, val, append(opts, options.Namespace(w.ns))...)
|
2021-07-14 17:11:37 +03:00
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (w *NamespaceStore) Write(ctx context.Context, key string, val interface{}, opts ...options.Option) error {
|
|
|
|
return w.s.Write(ctx, key, val, append(opts, options.Namespace(w.ns))...)
|
2021-07-14 17:11:37 +03:00
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (w *NamespaceStore) Delete(ctx context.Context, key string, opts ...options.Option) error {
|
|
|
|
return w.s.Delete(ctx, key, append(opts, options.Namespace(w.ns))...)
|
2021-07-14 17:11:37 +03:00
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (w *NamespaceStore) Exists(ctx context.Context, key string, opts ...options.Option) error {
|
|
|
|
return w.s.Exists(ctx, key, append(opts, options.Namespace(w.ns))...)
|
2021-07-14 17:11:37 +03:00
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (w *NamespaceStore) List(ctx context.Context, opts ...options.Option) ([]string, error) {
|
|
|
|
return w.s.List(ctx, append(opts, options.Namespace(w.ns))...)
|
2021-07-14 17:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|