fix to discoverer

pull/730/head
longXboy 4 years ago
parent 8f064855d9
commit 4444e7a638
  1. 4
      registry/registry.go
  2. 4
      transport/grpc/client.go
  3. 12
      transport/grpc/resolver/discovery/builder.go

@ -10,8 +10,8 @@ type Registrar interface {
Deregister(ctx context.Context, service *ServiceInstance) error
}
// Discovery is service discovery.
type Discovery interface {
// Discoverer is service discovery.
type Discoverer interface {
// Service return the service instances in memory according to the service name.
Fetch(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
// Watch creates a watcher according to the service name.

@ -39,7 +39,7 @@ func WithMiddleware(m middleware.Middleware) ClientOption {
}
// WithDiscovery with client registry.
func WithDiscovery(r registry.Discovery) ClientOption {
func WithDiscovery(r registry.Discoverer) ClientOption {
return func(o *clientOptions) {
o.discovery = r
}
@ -57,7 +57,7 @@ type clientOptions struct {
endpoint string
timeout time.Duration
middleware middleware.Middleware
discovery registry.Discovery
discovery registry.Discoverer
grpcOpts []grpc.DialOption
}

@ -21,15 +21,15 @@ func WithLogger(logger log.Logger) Option {
}
type builder struct {
registry registry.Discovery
logger log.Logger
discoverer registry.Discoverer
logger log.Logger
}
// NewBuilder creates a builder which is used to factory registry resolvers.
func NewBuilder(r registry.Discovery, opts ...Option) resolver.Builder {
func NewBuilder(r registry.Discoverer, opts ...Option) resolver.Builder {
b := &builder{
registry: r,
logger: log.DefaultLogger,
discoverer: r,
logger: log.DefaultLogger,
}
for _, o := range opts {
o(b)
@ -38,7 +38,7 @@ func NewBuilder(r registry.Discovery, opts ...Option) resolver.Builder {
}
func (d *builder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
w, err := d.registry.Watch(context.Background(), target.Endpoint)
w, err := d.discoverer.Watch(context.Background(), target.Endpoint)
if err != nil {
return nil, err
}

Loading…
Cancel
Save