2020-08-29 17:41:49 +03:00
|
|
|
package registry
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
2020-08-29 17:41:49 +03:00
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
type noopRegistry struct {
|
2020-09-03 15:11:05 +03:00
|
|
|
opts Options
|
|
|
|
}
|
2020-08-29 17:41:49 +03:00
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Init initialize registry
|
|
|
|
func (n *noopRegistry) Init(opts ...Option) error {
|
2020-09-03 15:11:05 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&n.opts)
|
|
|
|
}
|
2020-08-29 17:41:49 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Options returns options struct
|
|
|
|
func (n *noopRegistry) Options() Options {
|
2020-09-03 15:11:05 +03:00
|
|
|
return n.opts
|
2020-08-29 17:41:49 +03:00
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Connect opens connection to registry
|
|
|
|
func (n *noopRegistry) Connect(ctx context.Context) error {
|
2020-08-29 17:41:49 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Disconnect close connection to registry
|
|
|
|
func (n *noopRegistry) Disconnect(ctx context.Context) error {
|
2020-08-29 17:41:49 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Register registers service
|
2020-11-03 02:02:32 +03:00
|
|
|
func (n *noopRegistry) Register(ctx context.Context, svc *Service, opts ...RegisterOption) error {
|
2020-10-16 09:38:57 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Deregister deregisters service
|
2020-11-03 02:02:32 +03:00
|
|
|
func (n *noopRegistry) Deregister(ctx context.Context, svc *Service, opts ...DeregisterOption) error {
|
2020-10-16 09:38:57 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// GetService returns servive info
|
2020-11-03 02:02:32 +03:00
|
|
|
func (n *noopRegistry) GetService(ctx context.Context, name string, opts ...GetOption) ([]*Service, error) {
|
2020-08-29 17:41:49 +03:00
|
|
|
return []*Service{}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// ListServices listing services
|
2020-11-03 02:02:32 +03:00
|
|
|
func (n *noopRegistry) ListServices(ctx context.Context, opts ...ListOption) ([]*Service, error) {
|
2020-08-29 17:41:49 +03:00
|
|
|
return []*Service{}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Watch is used to watch for service changes
|
2020-11-03 02:02:32 +03:00
|
|
|
func (n *noopRegistry) Watch(ctx context.Context, opts ...WatchOption) (Watcher, error) {
|
2020-11-13 14:50:57 +03:00
|
|
|
return &noopWatcher{done: make(chan struct{}), opts: NewWatchOptions(opts...)}, nil
|
2020-08-29 17:41:49 +03:00
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// String returns registry string representation
|
|
|
|
func (n *noopRegistry) String() string {
|
2020-08-29 17:41:49 +03:00
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
2020-11-13 14:50:57 +03:00
|
|
|
type noopWatcher struct {
|
|
|
|
opts WatchOptions
|
|
|
|
done chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *noopWatcher) Next() (*Result, error) {
|
|
|
|
<-n.done
|
|
|
|
return nil, ErrWatcherStopped
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *noopWatcher) Stop() {
|
|
|
|
close(n.done)
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
// NewRegistry returns a new noop registry
|
|
|
|
func NewRegistry(opts ...Option) Registry {
|
2020-11-03 01:08:23 +03:00
|
|
|
return &noopRegistry{opts: NewOptions(opts...)}
|
2020-08-29 17:41:49 +03:00
|
|
|
}
|