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.
|
// Registry returns registry.
|
||||||
func (a *App) Registry() registry.Registry {
|
func (a *App) Registry() registry.Registrar {
|
||||||
return a.opts.registry
|
return a.opts.registry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,9 @@ type options struct {
|
|||||||
sigs []os.Signal
|
sigs []os.Signal
|
||||||
|
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
registry registry.Registry
|
registry registry.Registrar
|
||||||
servers []transport.Server
|
|
||||||
|
servers []transport.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID with service id.
|
// ID with service id.
|
||||||
@ -69,7 +70,7 @@ func Logger(logger log.Logger) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Registry with service registry.
|
// Registry with service registry.
|
||||||
func Registry(r registry.Registry) Option {
|
func Registry(r registry.Registrar) Option {
|
||||||
return func(o *options) { o.registry = r }
|
return func(o *options) { o.registry = r }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,20 @@ package registry
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
// Registry is service registry.
|
// Registrar is service registrar.
|
||||||
type Registry interface {
|
type Registrar interface {
|
||||||
// Register the registration.
|
// Register the registration.
|
||||||
Register(ctx context.Context, service *ServiceInstance) error
|
Register(ctx context.Context, service *ServiceInstance) error
|
||||||
// Deregister the registration.
|
// Deregister the registration.
|
||||||
Deregister(ctx context.Context, service *ServiceInstance) error
|
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 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 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.
|
// Watcher is service watcher.
|
||||||
|
@ -38,10 +38,10 @@ func WithMiddleware(m middleware.Middleware) ClientOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithRegistry with client registry.
|
// WithDiscovery with client registry.
|
||||||
func WithRegistry(r registry.Registry) ClientOption {
|
func WithDiscovery(r registry.Discovery) ClientOption {
|
||||||
return func(o *clientOptions) {
|
return func(o *clientOptions) {
|
||||||
o.registry = r
|
o.discovery = r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ type clientOptions struct {
|
|||||||
endpoint string
|
endpoint string
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
middleware middleware.Middleware
|
middleware middleware.Middleware
|
||||||
registry registry.Registry
|
discovery registry.Discovery
|
||||||
grpcOpts []grpc.DialOption
|
grpcOpts []grpc.DialOption
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,8 +86,8 @@ func dial(ctx context.Context, insecure bool, opts ...ClientOption) (*grpc.Clien
|
|||||||
grpc.WithTimeout(options.timeout),
|
grpc.WithTimeout(options.timeout),
|
||||||
grpc.WithUnaryInterceptor(UnaryClientInterceptor(options.middleware)),
|
grpc.WithUnaryInterceptor(UnaryClientInterceptor(options.middleware)),
|
||||||
}
|
}
|
||||||
if options.registry != nil {
|
if options.discovery != nil {
|
||||||
grpc.WithResolvers(discovery.NewBuilder(options.registry))
|
grpc.WithResolvers(discovery.NewBuilder(options.discovery))
|
||||||
}
|
}
|
||||||
if insecure {
|
if insecure {
|
||||||
grpcOpts = append(grpcOpts, grpc.WithInsecure())
|
grpcOpts = append(grpcOpts, grpc.WithInsecure())
|
||||||
|
@ -21,12 +21,12 @@ func WithLogger(logger log.Logger) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type builder struct {
|
type builder struct {
|
||||||
registry registry.Registry
|
registry registry.Discovery
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBuilder creates a builder which is used to factory registry resolvers.
|
// 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{
|
b := &builder{
|
||||||
registry: r,
|
registry: r,
|
||||||
logger: log.DefaultLogger,
|
logger: log.DefaultLogger,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user