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,17 +1,20 @@
package registry
import (
"errors"
)
import "fmt"
type noopRegistry struct{}
type noopRegistry struct {
opts Options
}
func (n *noopRegistry) Init(...Option) error {
func (n *noopRegistry) Init(opts ...Option) error {
for _, o := range opts {
o(&n.opts)
}
return nil
}
func (n *noopRegistry) Options() Options {
return Options{}
return n.opts
}
func (n *noopRegistry) Register(*Service, ...RegisterOption) error {
@@ -31,14 +34,20 @@ func (n *noopRegistry) ListServices(...ListOption) ([]*Service, error) {
}
func (n *noopRegistry) Watch(...WatchOption) (Watcher, error) {
return nil, errors.New("not implemented")
return nil, fmt.Errorf("not implemented")
}
func (n *noopRegistry) String() string {
return "noop"
}
// NewRegistry returns a new noop registry
func NewRegistry(...Option) Registry {
return &noopRegistry{}
// newRegistry returns a new noop registry
func newRegistry(opts ...Option) Registry {
options := NewOptions()
for _, o := range opts {
o(&options)
}
return &noopRegistry{opts: options}
}

View File

@@ -19,6 +19,13 @@ type Options struct {
Context context.Context
}
func NewOptions() Options {
return Options{
Logger: logger.DefaultLogger,
Context: context.Background(),
}
}
type RegisterOptions struct {
TTL time.Duration
// Other options for implementations of the interface

View File

@@ -13,7 +13,7 @@ const (
)
var (
DefaultRegistry Registry = NewRegistry()
DefaultRegistry Registry = newRegistry()
// ErrNotFound returned when GetService is called and no services found
ErrNotFound = errors.New("service not found")
// ErrWatcherStopped returned when when watcher is stopped