Documentation
¶
Index ¶
- func NewDiscover(client *api.Client, meta *micro.Meta, conf *ServiceConf) (micro.Discovery, error)
- func NewRegister(client *api.Client, meta *micro.Meta, conf *ServiceConf) (micro.Register, error)
- type DiscoverInstance
- type EventType
- type GatewayConf
- type RegisterInstance
- type ServiceConf
- type ServiceEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDiscover ¶
NewDiscover 创建发现器并返回统一发现接口。
func NewRegister ¶
NewRegister 创建一个 Consul 注册器实例并返回统一注册接口。
Types ¶
type DiscoverInstance ¶
type DiscoverInstance struct {
// contains filtered or unexported fields
}
DiscoverInstance 封装 Consul 网关发现逻辑。
func (*DiscoverInstance) GetService ¶
func (s *DiscoverInstance) GetService(method string) ([]*micro.ServiceNode, string, error)
GetService 根据 method 查询服务节点列表。
func (*DiscoverInstance) WatchEvent ¶
func (s *DiscoverInstance) WatchEvent(callback micro.WatchEventFunc)
WatchEvent 注册服务变更回调。
type GatewayConf ¶
GatewayConf 定义网关相关配置。
type RegisterInstance ¶
type RegisterInstance struct {
// contains filtered or unexported fields
}
RegisterInstance 封装 Consul 服务注册生命周期。
func (*RegisterInstance) Install ¶
func (s *RegisterInstance) Install(service *micro.ServiceNode) error
Install 将服务实例注册到 Consul。
func (*RegisterInstance) Uninstall ¶
func (s *RegisterInstance) Uninstall() error
Uninstall 将当前实例从 Consul 注销。
type ServiceConf ¶
type ServiceConf struct {
// 实例Id
InstanceId string `json:"instance_id"`
// 命名空间
Namespace string `json:"namespace"`
// 网卡
Network *micro.Network `json:"network"`
// 内核
Kernel *micro.Kernel `json:"kernel"`
// 最大重试次数, 间隔时间是TTL*5
MaxRetry uint32 `json:"max_retry"`
// 心跳/租约 TTL(秒), 最少是10s
TTL uint32 `json:"ttl"`
// 权重
Weight int `json:"weight"`
}
ServiceConf 定义服务实例在 Consul 注册场景下的配置。
func (*ServiceConf) Bootstrap ¶
func (sc *ServiceConf) Bootstrap()
Bootstrap 补齐 namespace/ttl/maxRetry/network/kernel 等默认值,避免下游逻辑出现零值陷阱
type ServiceEvent ¶
type ServiceEvent struct {
// Type 表示事件类型。
Type EventType
// Service 表示发生变化的节点对象。
Service *micro.ServiceNode
}
ServiceEvent 是发现层事件载体。
Click to show internal directories.
Click to hide internal directories.