diff --git a/registry/registry.go b/registry/registry.go index 9679567ce..584028551 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -10,8 +10,8 @@ type Registrar interface { Deregister(ctx context.Context, service *ServiceInstance) error } -// Instancer is service instancer. -type Instancer 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 53d661d37..3f3e3c6a8 100644 --- a/transport/grpc/client.go +++ b/transport/grpc/client.go @@ -39,9 +39,9 @@ func WithMiddleware(m middleware.Middleware) ClientOption { } // WithRegistry with client registry. -func WithRegistry(in registry.Instancer) ClientOption { +func WithRegistry(d registry.Discoverer) ClientOption { return func(o *clientOptions) { - o.instancer = in + o.discoverer = d } } @@ -57,7 +57,7 @@ type clientOptions struct { endpoint string timeout time.Duration middleware middleware.Middleware - instancer registry.Instancer + discoverer registry.Discoverer grpcOpts []grpc.DialOption } @@ -85,8 +85,8 @@ func dial(ctx context.Context, insecure bool, opts ...ClientOption) (*grpc.Clien var grpcOpts = []grpc.DialOption{ grpc.WithUnaryInterceptor(unaryClientInterceptor(options.middleware, options.timeout)), } - if options.instancer != nil { - grpcOpts = append(grpcOpts, grpc.WithResolvers(discovery.NewBuilder(options.instancer))) + if options.discoverer != nil { + grpcOpts = append(grpcOpts, grpc.WithResolvers(discovery.NewBuilder(options.discoverer))) } if insecure { grpcOpts = append(grpcOpts, grpc.WithInsecure()) diff --git a/transport/grpc/resolver/discovery/builder.go b/transport/grpc/resolver/discovery/builder.go index ec958b99a..aabe0e6d3 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 { - instancer registry.Instancer - logger log.Logger + discoverer registry.Discoverer + logger log.Logger } // NewBuilder creates a builder which is used to factory registry resolvers. -func NewBuilder(in registry.Instancer, opts ...Option) resolver.Builder { +func NewBuilder(d registry.Discoverer, opts ...Option) resolver.Builder { b := &builder{ - instancer: in, - logger: log.DefaultLogger, + discoverer: d, + logger: log.DefaultLogger, } for _, o := range opts { o(b) @@ -38,7 +38,7 @@ func NewBuilder(in registry.Instancer, opts ...Option) resolver.Builder { } func (d *builder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) { - w, err := d.instancer.Watch(context.Background(), target.Endpoint) + w, err := d.discoverer.Watch(context.Background(), target.Endpoint) if err != nil { return nil, err }