add a noop registry
This commit is contained in:
parent
51f8b4ae3d
commit
e8ea0f85e9
41
registry/noop/noop.go
Normal file
41
registry/noop/noop.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Package noop is a registry which does nothing
|
||||||
|
package noop
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/micro/go-micro/v3/registry"
|
||||||
|
)
|
||||||
|
|
||||||
|
type noopRegistry struct{}
|
||||||
|
|
||||||
|
func (n *noopRegistry) Init(o ...registry.Option) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopRegistry) Options() registry.Options {
|
||||||
|
return registry.Options{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopRegistry) Register(*registry.Service, ...registry.RegisterOption) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopRegistry) Deregister(*registry.Service, ...registry.DeregisterOption) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopRegistry) GetService(s string, o ...registry.GetOption) ([]*registry.Service, error) {
|
||||||
|
return []*registry.Service{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopRegistry) ListServices(...registry.ListOption) ([]*registry.Service, error) {
|
||||||
|
return []*registry.Service{}, nil
|
||||||
|
}
|
||||||
|
func (n *noopRegistry) Watch(...registry.WatchOption) (registry.Watcher, error) {
|
||||||
|
return nil, errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noopRegistry) String() string {
|
||||||
|
return "noop"
|
||||||
|
}
|
@ -595,6 +595,11 @@ func (g *grpcServer) Register() error {
|
|||||||
config := g.opts
|
config := g.opts
|
||||||
g.RUnlock()
|
g.RUnlock()
|
||||||
|
|
||||||
|
// only register if it exists or is not noop
|
||||||
|
if config.Registry == nil || config.Registry.String() == "noop" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
regFunc := func(service *registry.Service) error {
|
regFunc := func(service *registry.Service) error {
|
||||||
var regErr error
|
var regErr error
|
||||||
|
|
||||||
@ -779,6 +784,11 @@ func (g *grpcServer) Deregister() error {
|
|||||||
config := g.opts
|
config := g.opts
|
||||||
g.RUnlock()
|
g.RUnlock()
|
||||||
|
|
||||||
|
// only register if it exists or is not noop
|
||||||
|
if config.Registry == nil || config.Registry.String() == "noop" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// check the advertise address first
|
// check the advertise address first
|
||||||
// if it exists then use it, otherwise
|
// if it exists then use it, otherwise
|
||||||
// use the address
|
// use the address
|
||||||
|
@ -522,6 +522,11 @@ func (s *rpcServer) Register() error {
|
|||||||
config := s.Options()
|
config := s.Options()
|
||||||
s.RUnlock()
|
s.RUnlock()
|
||||||
|
|
||||||
|
// only register if it exists or is not noop
|
||||||
|
if config.Registry == nil || config.Registry.String() == "noop" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
regFunc := func(service *registry.Service) error {
|
regFunc := func(service *registry.Service) error {
|
||||||
// create registry options
|
// create registry options
|
||||||
rOpts := []registry.RegisterOption{
|
rOpts := []registry.RegisterOption{
|
||||||
@ -730,6 +735,11 @@ func (s *rpcServer) Deregister() error {
|
|||||||
config := s.Options()
|
config := s.Options()
|
||||||
s.RUnlock()
|
s.RUnlock()
|
||||||
|
|
||||||
|
// only register if it exists or is not noop
|
||||||
|
if config.Registry == nil || config.Registry.String() == "noop" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// check the advertise address first
|
// check the advertise address first
|
||||||
// if it exists then use it, otherwise
|
// if it exists then use it, otherwise
|
||||||
// use the address
|
// use the address
|
||||||
|
Loading…
Reference in New Issue
Block a user