minor improvements
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user