1
0
mirror of https://github.com/go-kratos/kratos.git synced 2024-12-26 20:54:38 +02:00

fix registry interface (#747)

This commit is contained in:
Tony Chen 2021-03-05 22:57:28 +08:00 committed by GitHub
parent f86c91849b
commit 8722894939
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 13 deletions

View File

@ -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.

View File

@ -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())

View File

@ -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
}