代码拉取完成,页面将自动刷新
// Package registry is service registry library, supports etcd, consul and nacos.
package registry
import "context"
// Registry is service registrar.
type Registry 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 {
// GetService return the service instances in memory according to the service name.
GetService(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
// Watch creates a watcher according to the service name.
Watch(ctx context.Context, serviceName string) (Watcher, error)
}
// Watcher is service watcher.
type Watcher interface {
// Next returns services in the following two cases:
// 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)
// Stop close the watcher.
Stop() error
}
// ServiceInstance is an instance of a service in a discovery system.
type ServiceInstance struct {
// ID is the unique instance ID as registered.
ID string `json:"id"`
// Name is the service name as registered.
Name string `json:"name"`
// Version is the version of the compiled.
Version string `json:"version"`
// Metadata is the kv pair metadata associated with the service instance.
Metadata map[string]string `json:"metadata"`
// 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
Endpoints []string `json:"endpoints"`
}
// NewServiceInstance creates a new instance
func NewServiceInstance(id string, name string, endpoints []string, opts ...Option) *ServiceInstance {
o := defaultOptions()
o.apply(opts...)
return &ServiceInstance{
ID: id,
Name: name,
Endpoints: endpoints,
Version: o.version,
Metadata: o.metadata,
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。