mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
parent
18d43d6006
commit
ef996c826a
4
app.go
4
app.go
@ -81,7 +81,7 @@ func (a *App) Run() error {
|
||||
})
|
||||
}
|
||||
if a.opts.registry != nil {
|
||||
if err := a.opts.registry.Register(a.instance); err != nil {
|
||||
if err := a.opts.registry.Register(a.opts.ctx, a.instance); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,7 @@ func (a *App) Run() error {
|
||||
// Stop gracefully stops the application.
|
||||
func (a *App) Stop() error {
|
||||
if a.opts.registry != nil {
|
||||
if err := a.opts.registry.Deregister(a.instance); err != nil {
|
||||
if err := a.opts.registry.Deregister(a.opts.ctx, a.instance); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
package registry
|
||||
|
||||
import "context"
|
||||
|
||||
// Registry is service registry.
|
||||
type Registry interface {
|
||||
// Register the registration.
|
||||
Register(service *ServiceInstance) error
|
||||
Register(ctx context.Context, service *ServiceInstance) error
|
||||
// Deregister the registration.
|
||||
Deregister(service *ServiceInstance) error
|
||||
Deregister(ctx context.Context, service *ServiceInstance) error
|
||||
// Service return the service instances in memory according to the service name.
|
||||
Service(name string) ([]*ServiceInstance, error)
|
||||
Service(ctx context.Context, name string) ([]*ServiceInstance, error)
|
||||
// Watch creates a watcher according to the service name.
|
||||
Watch(name string) (Watcher, error)
|
||||
Watch(ctx context.Context, name string) (Watcher, error)
|
||||
}
|
||||
|
||||
// Watcher is service watcher.
|
||||
|
@ -1,6 +1,8 @@
|
||||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/go-kratos/kratos/v2/registry"
|
||||
"google.golang.org/grpc/resolver"
|
||||
@ -36,7 +38,7 @@ func NewBuilder(r registry.Registry, 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(target.Endpoint)
|
||||
w, err := d.registry.Watch(context.Background(), target.Endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user