mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-26 03:52:12 +02:00
split naming registry
This commit is contained in:
parent
e10aa8ae75
commit
8f064855d9
2
app.go
2
app.go
@ -58,7 +58,7 @@ func (a *App) Server() []transport.Server {
|
||||
}
|
||||
|
||||
// Registry returns registry.
|
||||
func (a *App) Registry() registry.Registry {
|
||||
func (a *App) Registry() registry.Registrar {
|
||||
return a.opts.registry
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,9 @@ type options struct {
|
||||
sigs []os.Signal
|
||||
|
||||
logger log.Logger
|
||||
registry registry.Registry
|
||||
servers []transport.Server
|
||||
registry registry.Registrar
|
||||
|
||||
servers []transport.Server
|
||||
}
|
||||
|
||||
// ID with service id.
|
||||
@ -69,7 +70,7 @@ func Logger(logger log.Logger) Option {
|
||||
}
|
||||
|
||||
// Registry with service registry.
|
||||
func Registry(r registry.Registry) Option {
|
||||
func Registry(r registry.Registrar) Option {
|
||||
return func(o *options) { o.registry = r }
|
||||
}
|
||||
|
||||
|
@ -2,16 +2,20 @@ package registry
|
||||
|
||||
import "context"
|
||||
|
||||
// Registry is service registry.
|
||||
type Registry interface {
|
||||
// Registrar is service registrar.
|
||||
type Registrar interface {
|
||||
// Register the registration.
|
||||
Register(ctx context.Context, service *ServiceInstance) error
|
||||
// Deregister the registration.
|
||||
Deregister(ctx context.Context, service *ServiceInstance) error
|
||||
}
|
||||
|
||||
// Discovery is service discovery.
|
||||
type Discovery interface {
|
||||
// Service return the service instances in memory according to the service name.
|
||||
Service(ctx context.Context, name string) ([]*ServiceInstance, error)
|
||||
Fetch(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
|
||||
// Watch creates a watcher according to the service name.
|
||||
Watch(ctx context.Context, name string) (Watcher, error)
|
||||
Watch(ctx context.Context, serviceName string) (Watcher, error)
|
||||
}
|
||||
|
||||
// Watcher is service watcher.
|
||||
|
@ -38,10 +38,10 @@ func WithMiddleware(m middleware.Middleware) ClientOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithRegistry with client registry.
|
||||
func WithRegistry(r registry.Registry) ClientOption {
|
||||
// WithDiscovery with client registry.
|
||||
func WithDiscovery(r registry.Discovery) ClientOption {
|
||||
return func(o *clientOptions) {
|
||||
o.registry = r
|
||||
o.discovery = r
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ type clientOptions struct {
|
||||
endpoint string
|
||||
timeout time.Duration
|
||||
middleware middleware.Middleware
|
||||
registry registry.Registry
|
||||
discovery registry.Discovery
|
||||
grpcOpts []grpc.DialOption
|
||||
}
|
||||
|
||||
@ -86,8 +86,8 @@ func dial(ctx context.Context, insecure bool, opts ...ClientOption) (*grpc.Clien
|
||||
grpc.WithTimeout(options.timeout),
|
||||
grpc.WithUnaryInterceptor(UnaryClientInterceptor(options.middleware)),
|
||||
}
|
||||
if options.registry != nil {
|
||||
grpc.WithResolvers(discovery.NewBuilder(options.registry))
|
||||
if options.discovery != nil {
|
||||
grpc.WithResolvers(discovery.NewBuilder(options.discovery))
|
||||
}
|
||||
if insecure {
|
||||
grpcOpts = append(grpcOpts, grpc.WithInsecure())
|
||||
|
@ -21,12 +21,12 @@ func WithLogger(logger log.Logger) Option {
|
||||
}
|
||||
|
||||
type builder struct {
|
||||
registry registry.Registry
|
||||
registry registry.Discovery
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewBuilder creates a builder which is used to factory registry resolvers.
|
||||
func NewBuilder(r registry.Registry, opts ...Option) resolver.Builder {
|
||||
func NewBuilder(r registry.Discovery, opts ...Option) resolver.Builder {
|
||||
b := &builder{
|
||||
registry: r,
|
||||
logger: log.DefaultLogger,
|
||||
|
Loading…
x
Reference in New Issue
Block a user