Documentation
¶
Index ¶
- Constants
- Variables
- func Deregister(s *Service, opts ...DeregisterOption) error
- func Register(s *Service, opts ...RegisterOption) error
- func String() string
- type DeregisterOption
- type DeregisterOptions
- type Event
- type EventType
- type GetOption
- type GetOptions
- type ListOption
- type ListOptions
- type Node
- type Option
- type Options
- type PluginRegistry
- func (that *PluginRegistry) AfterListen(addr net.Addr) (err error)
- func (that *PluginRegistry) AfterRegRouter(handler *drpc.Handler) error
- func (that *PluginRegistry) BeforeCloseEndpoint(_ drpc.Endpoint) error
- func (that *PluginRegistry) Deregister() error
- func (that *PluginRegistry) Name() string
- func (that *PluginRegistry) Register() error
- type RegisterOption
- type RegisterOptions
- type Registry
- type Result
- type Service
- type WatchOption
- type WatchOptions
- type Watcher
Constants ¶
View Source
const ( DefaultRegisterInterval = time.Second * 30 DefaultRegisterTTL = time.Second * 90 )
Variables ¶
View Source
var ( DefaultRegistry = NewRegistry() ErrNotFound = errors.New("service not found") ErrWatcherStopped = errors.New("watcher stopped") )
Functions ¶
func Deregister ¶ added in v0.6.1
func Deregister(s *Service, opts ...DeregisterOption) error
Deregister 从注册表这中注销节点
func Register ¶ added in v0.6.1
func Register(s *Service, opts ...RegisterOption) error
Register 注册节点到注册表
Types ¶
type DeregisterOption ¶
type DeregisterOption func(*DeregisterOptions)
func OptDeregisterContext ¶ added in v1.2.0
func OptDeregisterContext(ctx context.Context) DeregisterOption
type DeregisterOptions ¶
DeregisterOptions 取消注册参数
type Event ¶
type Event struct {
// Id 注册的id
Id string
// Type 事件类型
Type EventType
// Timestamp 事件发生事件
Timestamp time.Time
// Service 注册的服务
Service *Service
}
Event 事件
type GetOptions ¶
type ListOption ¶
type ListOption func(*ListOptions)
func OptListContext ¶ added in v1.2.0
func OptListContext(ctx context.Context) ListOption
type ListOptions ¶
type Node ¶
type Node struct {
Id string `json:"id"`
Address string `json:"address"`
Paths []string `json:"paths"`
Metadata map[string]string `json:"metadata"`
}
Node 节点
type Option ¶
type Option func(*Options)
func OptLeasesInterval ¶ added in v1.2.0
OptLeasesInterval 租约续期时间
func OptServiceVersion ¶ added in v1.2.0
OptServiceVersion 设置服务版本
type Options ¶
type Options struct {
AddrList []string // 地址列表
Timeout time.Duration // 超时时间
Secure bool // 是否加密
TLSConfig *tls.Config // tls证书配置
Context context.Context // 上下文系信息
}
Options 配置
type PluginRegistry ¶
type PluginRegistry struct {
// contains filtered or unexported fields
}
func NewRegistryPlugin ¶
func NewRegistryPlugin(registry Registry) *PluginRegistry
NewRegistryPlugin 创建服务注册插件
func (*PluginRegistry) AfterListen ¶
func (that *PluginRegistry) AfterListen(addr net.Addr) (err error)
AfterListen 服务启动成功,监听成功后,进行服务注册
func (*PluginRegistry) AfterRegRouter ¶
func (that *PluginRegistry) AfterRegRouter(handler *drpc.Handler) error
func (*PluginRegistry) BeforeCloseEndpoint ¶
func (that *PluginRegistry) BeforeCloseEndpoint(_ drpc.Endpoint) error
BeforeCloseEndpoint 关闭服务之前先取消注册
func (*PluginRegistry) Name ¶
func (that *PluginRegistry) Name() string
type RegisterOption ¶
type RegisterOption func(*RegisterOptions)
func OptRegisterContext ¶ added in v1.2.0
func OptRegisterContext(ctx context.Context) RegisterOption
OptRegisterContext 设置注册服务的上下文
func OptRegisterTTL ¶ added in v1.2.0
func OptRegisterTTL(t time.Duration) RegisterOption
OptRegisterTTL 设置服务的生存时间
type RegisterOptions ¶
RegisterOptions 注册配置信息
type Registry ¶
type Registry interface {
Init(...Option) error
Options() Options
Register(*Service, ...RegisterOption) error
Deregister(*Service, ...DeregisterOption) error
GetService(string, ...GetOption) ([]*Service, error)
ListServices(...ListOption) ([]*Service, error)
Watch(...WatchOption) (Watcher, error)
String() string
}
Registry 服务注册接口
func NewRegistry ¶
type Service ¶
type Service struct {
Name string `json:"name"`
Version string `json:"version"`
Metadata map[string]string `json:"metadata"`
Nodes []*Node `json:"nodes"`
}
Service 服务
func GetService ¶ added in v0.6.1
GetService 通过服务名获取服务列表,为什么返回的是一个数组?因为服务是有版本区别的,多个版本的服务是可以共存的
type WatchOption ¶
type WatchOption func(*WatchOptions)
func OptWatchContext ¶ added in v1.2.0
func OptWatchContext(ctx context.Context) WatchOption
OptWatchContext 监视器的上下文
func OptWatchService ¶ added in v1.2.0
func OptWatchService(name string) WatchOption
OptWatchService 监视器监听指定的服务
type WatchOptions ¶
WatchOptions 监视器参数
Click to show internal directories.
Click to hide internal directories.