From 4444e7a638d8add3ff9941a8049f3b168bc5e939 Mon Sep 17 00:00:00 2001 From: longXboy Date: Sun, 28 Feb 2021 15:32:45 +0800 Subject: [PATCH] fix to discoverer --- registry/registry.go | 4 ++-- transport/grpc/client.go | 4 ++-- transport/grpc/resolver/discovery/builder.go | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/registry/registry.go b/registry/registry.go index 748ed5549..584028551 100644 --- a/registry/registry.go +++ b/registry/registry.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. diff --git a/transport/grpc/client.go b/transport/grpc/client.go index 8f6131686..5330ab228 100644 --- a/transport/grpc/client.go +++ b/transport/grpc/client.go @@ -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 } diff --git a/transport/grpc/resolver/discovery/builder.go b/transport/grpc/resolver/discovery/builder.go index 5d7b5c1d4..aa063a519 100644 --- a/transport/grpc/resolver/discovery/builder.go +++ b/transport/grpc/resolver/discovery/builder.go @@ -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 }