Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultNodeBuilder 是默认的节点构建器 DefaultNodeBuilder = func(id string, address string, metadata map[string]string) (Node, error) { return Node{ ID: id, Address: address, Metadata: metadata, Weight: 100, }, nil } )
View Source
var ( // ErrNoAvailable 是没有可用节点的错误 ErrNoAvailable = errors.New("no available node") )
Functions ¶
This section is empty.
Types ¶
type BalancerType ¶
type BalancerType interface {
// Pick 从节点列表中选择一个节点
Pick(ctx context.Context, nodes []Node) (Node, error)
}
BalancerType 是负载均衡器接口类型
type HealthCheckParams ¶
HealthCheckParams 是健康检查参数
type Node ¶
type Node struct {
// ID 是节点的唯一标识符
ID string
// Address 是节点的地址
Address string
// Metadata 是节点的元数据
Metadata map[string]string
// Weight 是节点的权重
Weight int64
}
Node 是一个节点
type NodeBuilderFunc ¶
NodeBuilderFunc 构建节点
type Option ¶
type Option func(o *options)
Option 是选择器选项
func WithHealthCheck ¶
func WithHealthCheck(enable bool, params HealthCheckParams) Option
WithHealthCheck 选项用于设置健康检查
func WithNodeBuilder ¶
func WithNodeBuilder(builder NodeBuilderFunc) Option
WithNodeBuilder 选项用于设置节点构建器
type RoundRobin ¶
type RoundRobin struct {
// contains filtered or unexported fields
}
RoundRobin 是轮询负载均衡器
type Selector ¶
type Selector interface {
// Select 选择一个节点
Select(ctx context.Context) (Node, error)
// Update 更新节点列表
Update(nodes []Node) error
// Apply 应用过滤器
Apply(filters ...FilterFunc)
}
Selector 是节点选择器接口
Click to show internal directories.
Click to hide internal directories.