1 Star 0 Fork 0

yzsunjianguo/sponge

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
registry.go 2.06 KB
一键复制 编辑 原始数据 按行查看 历史
yzsunjianguo 提交于 2024-02-08 14:53 . init
// 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,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yzsunjianguo/sponge.git
git@gitee.com:yzsunjianguo/sponge.git
yzsunjianguo
sponge
sponge
v1.0.3

搜索帮助