1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-22 03:38:41 +02:00
kratos/registry/registry.go

48 lines
1.7 KiB
Go
Raw Normal View History

2021-02-17 17:14:47 +08:00
package registry
import "context"
2021-02-28 13:39:45 +08:00
// Registrar is service registrar.
type Registrar interface {
2021-02-17 17:14:47 +08:00
// Register the registration.
Register(ctx context.Context, service *ServiceInstance) error
2021-02-17 17:14:47 +08:00
// Deregister the registration.
Deregister(ctx context.Context, service *ServiceInstance) error
2021-02-28 13:39:45 +08:00
}
// Discovery is service discovery.
type Discovery interface {
// GetService return the service instances in memory according to the service name.
GetService(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
2021-02-17 17:14:47 +08:00
// Watch creates a watcher according to the service name.
2021-02-28 13:39:45 +08:00
Watch(ctx context.Context, serviceName string) (Watcher, error)
2021-02-17 17:14:47 +08:00
}
// Watcher is service watcher.
type Watcher interface {
2021-04-14 13:54:14 +08:00
// Next returns services in the following two cases:
2021-02-17 17:14:47 +08:00
// 1.the first time to watch and the service instance list is not empty.
// 2.any service instance changes found.
// if the above two conditions are not met, it will block until context deadline exceeded or canceled
Next() ([]*ServiceInstance, error)
2021-04-14 13:54:14 +08:00
// Stop close the watcher.
Stop() error
2021-02-17 17:14:47 +08:00
}
// ServiceInstance is an instance of a service in a discovery system.
type ServiceInstance struct {
// ID is the unique instance ID as registered.
2021-03-15 17:06:06 +08:00
ID string `json:"id"`
2021-02-17 17:14:47 +08:00
// Name is the service name as registered.
2021-03-15 17:06:06 +08:00
Name string `json:"name"`
2021-02-17 17:14:47 +08:00
// Version is the version of the compiled.
2021-03-15 17:06:06 +08:00
Version string `json:"version"`
2021-02-17 17:14:47 +08:00
// Metadata is the kv pair metadata associated with the service instance.
2021-03-15 17:06:06 +08:00
Metadata map[string]string `json:"metadata"`
2021-02-17 17:14:47 +08:00
// Endpoints is endpoint addresses of the service instance.
// schema:
// http://127.0.0.1:8000?isSecure=false
// grpc://127.0.0.1:9000?isSecure=false
2021-03-15 17:06:06 +08:00
Endpoints []string `json:"endpoints"`
2021-02-17 17:14:47 +08:00
}