fix linting (#4)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -2,45 +2,58 @@ package store
|
||||
|
||||
import "context"
|
||||
|
||||
type NoopStore struct {
|
||||
type noopStore struct {
|
||||
opts Options
|
||||
}
|
||||
|
||||
func (n *NoopStore) Init(opts ...Option) error {
|
||||
func NewStore(opts ...Option) Store {
|
||||
return &noopStore{opts: NewOptions(opts...)}
|
||||
}
|
||||
|
||||
// Init initialize store
|
||||
func (n *noopStore) Init(opts ...Option) error {
|
||||
for _, o := range opts {
|
||||
o(&n.opts)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NoopStore) Options() Options {
|
||||
// Options returns Options struct
|
||||
func (n *noopStore) Options() Options {
|
||||
return n.opts
|
||||
}
|
||||
|
||||
func (n *NoopStore) String() string {
|
||||
// String returns string representation
|
||||
func (n *noopStore) String() string {
|
||||
return "noop"
|
||||
}
|
||||
|
||||
func (n *NoopStore) Read(ctx context.Context, key string, opts ...ReadOption) ([]*Record, error) {
|
||||
// Read reads store value by key
|
||||
func (n *noopStore) Read(ctx context.Context, key string, opts ...ReadOption) ([]*Record, error) {
|
||||
return []*Record{}, nil
|
||||
}
|
||||
|
||||
func (n *NoopStore) Write(ctx context.Context, r *Record, opts ...WriteOption) error {
|
||||
// Write writes store record
|
||||
func (n *noopStore) Write(ctx context.Context, r *Record, opts ...WriteOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NoopStore) Delete(ctx context.Context, key string, opts ...DeleteOption) error {
|
||||
// Delete removes store value by key
|
||||
func (n *noopStore) Delete(ctx context.Context, key string, opts ...DeleteOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NoopStore) List(ctx context.Context, opts ...ListOption) ([]string, error) {
|
||||
// List lists store
|
||||
func (n *noopStore) List(ctx context.Context, opts ...ListOption) ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (n *NoopStore) Connect(ctx context.Context) error {
|
||||
// Connect connects to store
|
||||
func (n *noopStore) Connect(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NoopStore) Disconnect(ctx context.Context) error {
|
||||
// Disconnect disconnects from store
|
||||
func (n *noopStore) Disconnect(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
@@ -10,14 +10,16 @@ import (
|
||||
|
||||
var (
|
||||
// ErrNotFound is returned when a key doesn't exist
|
||||
ErrNotFound = errors.New("not found")
|
||||
DefaultStore Store = &NoopStore{opts: NewOptions()}
|
||||
ErrNotFound = errors.New("not found")
|
||||
// DefaultStore is the global default store
|
||||
DefaultStore Store = NewStore()
|
||||
)
|
||||
|
||||
// Store is a data storage interface
|
||||
type Store interface {
|
||||
// Init initialises the store. It must perform any required setup on the backing storage implementation and check that it is ready for use, returning any errors.
|
||||
Init(opts ...Option) error
|
||||
// Connect is used when store needs to be connected
|
||||
Connect(ctx context.Context) error
|
||||
// Options allows you to view the current options.
|
||||
Options() Options
|
||||
|
Reference in New Issue
Block a user