Documentation ¶
Index ¶
- Variables
- type Balancer
- type ConsistentHashWeight
- func (c *ConsistentHashWeight[I, T]) Add(instance T)
- func (c *ConsistentHashWeight[I, T]) Get(id I) (t T)
- func (c *ConsistentHashWeight[I, T]) GetInstances() []T
- func (c *ConsistentHashWeight[I, T]) Remove(instanceId I)
- func (c *ConsistentHashWeight[I, T]) Select(opts ...*SelectOptions) (t T, err error)
- func (c *ConsistentHashWeight[I, T]) Update(instance T)
- type Item
- type MetadataItem
- type RoundRobin
- type SelectOptions
- type WeightRoundRobin
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrNoInstance = errors.New("no instance") // 没有实例
)
Functions ¶
This section is empty.
Types ¶
type Balancer ¶
type Balancer[I constraints.Ordered, T Item[I]] interface { // Select 选择一个实例,如果没有实例则返回 ErrNoInstance Select(opts ...*SelectOptions) (T, error) // Add 添加一个实例 Add(instance T) // Remove 移除一个实例 Remove(instance I) // GetInstances 获取所有实例 GetInstances() []T }
type ConsistentHashWeight ¶
type ConsistentHashWeight[I constraints.Ordered, T Item[I]] struct { // contains filtered or unexported fields }
ConsistentHashWeight 一致性哈希权重负载均衡器
func NewConsistentHashWeight ¶
func NewConsistentHashWeight[I constraints.Ordered, T Item[I]](replicas int) *ConsistentHashWeight[I, T]
NewConsistentHashWeight 创建一致性哈希权重负载均衡器
func (*ConsistentHashWeight[I, T]) Add ¶
func (c *ConsistentHashWeight[I, T]) Add(instance T)
func (*ConsistentHashWeight[I, T]) Get ¶
func (c *ConsistentHashWeight[I, T]) Get(id I) (t T)
func (*ConsistentHashWeight[I, T]) GetInstances ¶
func (c *ConsistentHashWeight[I, T]) GetInstances() []T
func (*ConsistentHashWeight[I, T]) Remove ¶
func (c *ConsistentHashWeight[I, T]) Remove(instanceId I)
func (*ConsistentHashWeight[I, T]) Select ¶
func (c *ConsistentHashWeight[I, T]) Select(opts ...*SelectOptions) (t T, err error)
func (*ConsistentHashWeight[I, T]) Update ¶
func (c *ConsistentHashWeight[I, T]) Update(instance T)
type Item ¶
type Item[I constraints.Ordered] interface { // GetId 返回唯一标识 GetId() I // GetWeight 返回权重 GetWeight() int }
Item 负载均衡器的实例
type MetadataItem ¶
type MetadataItem[I constraints.Ordered, M any] interface { Item[I] // GetMetadata 返回元数据 GetMetadata() M }
MetadataItem 元数据负载均衡器的实例
type RoundRobin ¶
type RoundRobin[I constraints.Ordered, T Item[I]] struct { // contains filtered or unexported fields }
RoundRobin 轮询负载均衡器
func NewRoundRobin ¶
func NewRoundRobin[I constraints.Ordered, T Item[I]]() *RoundRobin[I, T]
func (*RoundRobin[I, T]) Add ¶
func (r *RoundRobin[I, T]) Add(instance T)
func (*RoundRobin[I, T]) GetInstances ¶
func (r *RoundRobin[I, T]) GetInstances() []T
func (*RoundRobin[I, T]) Remove ¶
func (r *RoundRobin[I, T]) Remove(instanceId I)
func (*RoundRobin[I, T]) Select ¶
func (r *RoundRobin[I, T]) Select(opts ...*SelectOptions) (t T, err error)
type SelectOptions ¶
type SelectOptions struct {
ConsistencyKey string // ConsistencyKey 一致性哈希的键
}
func NewSelectOptions ¶
func NewSelectOptions() *SelectOptions
NewSelectOptions 创建一个新的 SelectOptions
func (*SelectOptions) Apply ¶
func (o *SelectOptions) Apply(opts ...*SelectOptions) *SelectOptions
Apply 应用多个选项
func (*SelectOptions) WithConsistencyKey ¶
func (o *SelectOptions) WithConsistencyKey(consistencyKey string) *SelectOptions
WithConsistencyKey 设置 ConsistencyKey
type WeightRoundRobin ¶
type WeightRoundRobin[I constraints.Ordered, T Item[I]] struct { // contains filtered or unexported fields }
WeightRoundRobin 加权轮询负载均衡器
func NewWeightRoundRobin ¶
func NewWeightRoundRobin[I constraints.Ordered, T Item[I]]() *WeightRoundRobin[I, T]
NewWeightRoundRobin 创建一个加权轮询负载均衡器
func (*WeightRoundRobin[I, T]) Add ¶
func (r *WeightRoundRobin[I, T]) Add(instance T)
func (*WeightRoundRobin[I, T]) GetInstances ¶
func (r *WeightRoundRobin[I, T]) GetInstances() []T
func (*WeightRoundRobin[I, T]) Remove ¶
func (r *WeightRoundRobin[I, T]) Remove(instanceId I)
func (*WeightRoundRobin[I, T]) Select ¶
func (r *WeightRoundRobin[I, T]) Select(opts ...*SelectOptions) (t T, err error)
Click to show internal directories.
Click to hide internal directories.