add noop broker and noop store (#30)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-09-03 15:11:05 +03:00
committed by GitHub
parent 0252addf05
commit c062aab1a9
8 changed files with 126 additions and 16 deletions

View File

@@ -1,13 +1,26 @@
package store
type noopStore struct{}
type noopStore struct {
opts Options
}
func newStore(opts ...Option) Store {
options := NewOptions()
for _, o := range opts {
o(&options)
}
return &noopStore{opts: options}
}
func (n *noopStore) Init(opts ...Option) error {
for _, o := range opts {
o(&n.opts)
}
return nil
}
func (n *noopStore) Options() Options {
return Options{}
return n.opts
}
func (n *noopStore) String() string {

View File

@@ -23,6 +23,13 @@ type Options struct {
Context context.Context
}
func NewOptions() Options {
return Options{
Logger: logger.DefaultLogger,
Context: context.Background(),
}
}
// Option sets values in Options
type Option func(o *Options)

View File

@@ -9,8 +9,8 @@ import (
var (
// ErrNotFound is returned when a key doesn't exist
ErrNotFound = errors.New("not found")
DefaultStore Store
ErrNotFound = errors.New("not found")
DefaultStore Store = newStore()
)
// Store is a data storage interface