fixed struct alignment && refactor linter (#369)
All checks were successful
test / test (push) Successful in 42s

## Pull Request template
Please, go through these steps before clicking submit on this PR.

1. Give a descriptive title to your PR.
2. Provide a description of your changes.
3. Make sure you have some relevant tests.
4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable).

**PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING**

Reviewed-on: #369
Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru>
Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
This commit is contained in:
2024-12-09 16:23:25 +03:00
parent b6a0e4d983
commit 38c5fe8b5a
67 changed files with 480 additions and 398 deletions

View File

@@ -96,15 +96,15 @@ func (m *memoryStore) list(prefix string, limit, offset uint) []string {
if limit != 0 || offset != 0 {
sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] })
sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] })
end := len(allKeys)
end := uint(len(allKeys))
if limit > 0 {
calcLimit := int(offset + limit)
calcLimit := offset + limit
if calcLimit < end {
end = calcLimit
}
}
if int(offset) >= end {
if offset >= end {
return nil
}
return allKeys[offset:end]

View File

@@ -12,15 +12,18 @@ import (
var _ Store = (*noopStore)(nil)
type noopStore struct {
mu sync.Mutex
watchers map[string]Watcher
funcRead FuncRead
funcWrite FuncWrite
funcExists FuncExists
funcList FuncList
funcDelete FuncDelete
watchers map[string]Watcher
funcRead FuncRead
funcWrite FuncWrite
funcExists FuncExists
funcList FuncList
funcDelete FuncDelete
opts Options
isConnected atomic.Int32
mu sync.Mutex
}
func (n *noopStore) Live() bool {
@@ -35,7 +38,7 @@ func (n *noopStore) Health() bool {
return true
}
func NewStore(opts ...Option) *noopStore {
func NewStore(opts ...Option) Store {
options := NewOptions(opts...)
return &noopStore{opts: options}
}
@@ -94,7 +97,7 @@ func (n *noopStore) Read(ctx context.Context, key string, val interface{}, opts
return n.funcRead(ctx, key, val, opts...)
}
func (n *noopStore) fnRead(ctx context.Context, key string, val interface{}, opts ...ReadOption) error {
func (n *noopStore) fnRead(ctx context.Context, _ string, _ interface{}, _ ...ReadOption) error {
select {
case <-ctx.Done():
return ctx.Err()
@@ -112,7 +115,7 @@ func (n *noopStore) Delete(ctx context.Context, key string, opts ...DeleteOption
return n.funcDelete(ctx, key, opts...)
}
func (n *noopStore) fnDelete(ctx context.Context, key string, opts ...DeleteOption) error {
func (n *noopStore) fnDelete(ctx context.Context, _ string, _ ...DeleteOption) error {
select {
case <-ctx.Done():
return ctx.Err()
@@ -130,7 +133,7 @@ func (n *noopStore) Exists(ctx context.Context, key string, opts ...ExistsOption
return n.funcExists(ctx, key, opts...)
}
func (n *noopStore) fnExists(ctx context.Context, key string, opts ...ExistsOption) error {
func (n *noopStore) fnExists(ctx context.Context, _ string, _ ...ExistsOption) error {
select {
case <-ctx.Done():
return ctx.Err()
@@ -148,7 +151,7 @@ func (n *noopStore) Write(ctx context.Context, key string, val interface{}, opts
return n.funcWrite(ctx, key, val, opts...)
}
func (n *noopStore) fnWrite(ctx context.Context, key string, val interface{}, opts ...WriteOption) error {
func (n *noopStore) fnWrite(ctx context.Context, _ string, _ interface{}, _ ...WriteOption) error {
select {
case <-ctx.Done():
return ctx.Err()
@@ -200,13 +203,13 @@ func (n *noopStore) connect(ctx context.Context) error {
}
type watcher struct {
opts WatchOptions
ch chan Event
exit chan bool
id string
ch chan Event
opts WatchOptions
}
func (m *noopStore) Watch(ctx context.Context, opts ...WatchOption) (Watcher, error) {
func (n *noopStore) Watch(_ context.Context, opts ...WatchOption) (Watcher, error) {
id, err := id.New()
if err != nil {
return nil, err
@@ -223,9 +226,9 @@ func (m *noopStore) Watch(ctx context.Context, opts ...WatchOption) (Watcher, er
opts: wo,
}
m.mu.Lock()
m.watchers[w.id] = w
m.mu.Unlock()
n.mu.Lock()
n.watchers[w.id] = w
n.mu.Unlock()
return w, nil
}

View File

@@ -15,6 +15,13 @@ import (
// Options contains configuration for the Store
type Options struct {
// Name specifies store name
Name string
// Namespace of the records
Namespace string
// Separator used as key parts separator
Separator string
// Meter used for metrics
Meter meter.Meter
// Tracer used for tracing
@@ -25,22 +32,17 @@ type Options struct {
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
// Timeout specifies timeout duration for all operations
Timeout time.Duration
// LazyConnect creates a connection when using store
LazyConnect bool
}

View File

@@ -16,7 +16,7 @@ var (
// 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()
DefaultStore = NewStore()
// DefaultSeparator is the gloabal default key parts separator
DefaultSeparator = "/"
)