minor improvements

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2022-11-07 14:53:58 +03:00
parent 4c2f12a419
commit 396387d1e8
7 changed files with 125 additions and 32 deletions

View File

@@ -2,7 +2,6 @@ package store
import (
"context"
"path/filepath"
"sort"
"strings"
"time"
@@ -33,12 +32,11 @@ type memoryStore struct {
}
func (m *memoryStore) key(prefix, key string) string {
return filepath.Join(prefix, key)
return prefix + m.opts.Separator + key
}
func (m *memoryStore) exists(prefix, key string) error {
key = m.key(prefix, key)
_, found := m.store.Get(key)
if !found {
return ErrNotFound

View File

@@ -30,6 +30,8 @@ type Options struct {
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
@@ -41,11 +43,12 @@ type Options struct {
// NewOptions creates options struct
func NewOptions(opts ...Option) Options {
options := Options{
Logger: logger.DefaultLogger,
Context: context.Background(),
Codec: codec.DefaultCodec,
Tracer: tracer.DefaultTracer,
Meter: meter.DefaultMeter,
Logger: logger.DefaultLogger,
Context: context.Background(),
Codec: codec.DefaultCodec,
Tracer: tracer.DefaultTracer,
Meter: meter.DefaultMeter,
Separator: DefaultSeparator,
}
for _, o := range opts {
o(&options)
@@ -98,6 +101,13 @@ func Name(n string) Option {
}
}
// Separator the value used as key parts separator
func Separator(s string) Option {
return func(o *Options) {
o.Separator = s
}
}
// Namespace sets namespace of the store
func Namespace(ns string) Option {
return func(o *Options) {

View File

@@ -13,6 +13,8 @@ var (
ErrInvalidKey = errors.New("invalid key")
// DefaultStore is the global default store
DefaultStore = NewStore()
// DefaultSeparator is the gloabal default key parts separator
DefaultSeparator = "/"
)
// Store is a data storage interface