Documentation
¶
Index ¶
Constants ¶
const (
FALLBACK = "fallback"
)
const (
WRR = "wrr"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FallbackSelector ¶
type FallbackSelector[T Item] struct { // contains filtered or unexported fields }
FallbackSelector implements a selector that prioritizes a primary item and falls back to a secondary item if the primary is disabled. It iterates through a list of items and selects the first one that is not disabled. It conforms to the Selector interface.
func NewFallbackSelector ¶
func NewFallbackSelector[T Item]() *FallbackSelector[T]
NewFallbackSelector creates a new FallbackSelector.
func (*FallbackSelector[T]) AddItem ¶
func (s *FallbackSelector[T]) AddItem(item T)
AddItem adds an item to the selector. Items will be tried in the order they are added.
func (*FallbackSelector[T]) GetType ¶
func (s *FallbackSelector[T]) GetType() string
func (*FallbackSelector[T]) Select ¶
func (s *FallbackSelector[T]) Select() (item T, err error)
Select chooses an item. It iterates through the configured items and returns the first item that is not disabled. It returns an error if no suitable item can be selected.
func (*FallbackSelector[T]) TotalConfigWeight ¶
func (s *FallbackSelector[T]) TotalConfigWeight() int
TotalConfigWeight returns 0 for FallbackSelector as weights are not applicable.
type WeightedItem ¶
type WeightedItem interface {
Item
// GetConfigWeight returns the configured weight of the item.
GetConfigWeight() int
// GetCurrentWeight returns the current weight of the item (used by the WRR algorithm).
GetCurrentWeight() int
// SetCurrentWeight sets the current weight of the item.
SetCurrentWeight(int)
}
WeightedItem defines the interface that items managed by the generic WRR selector must implement.
type WeightedRoundRobinSelector ¶
type WeightedRoundRobinSelector[T WeightedItem] struct { // contains filtered or unexported fields }
WeightedRoundRobinSelector is a generic implementation of the Smooth Weighted Round Robin algorithm.
func NewWeightedRoundRobinSelector ¶
func NewWeightedRoundRobinSelector[T WeightedItem]() *WeightedRoundRobinSelector[T]
NewWeightedRoundRobinSelector creates a new generic WeightedRoundRobinSelector.
func (*WeightedRoundRobinSelector[T]) AddItem ¶
func (s *WeightedRoundRobinSelector[T]) AddItem(item T)
AddItem adds an item to the selector.
func (*WeightedRoundRobinSelector[T]) GetType ¶
func (s *WeightedRoundRobinSelector[T]) GetType() string
func (*WeightedRoundRobinSelector[T]) Select ¶
func (s *WeightedRoundRobinSelector[T]) Select() (item T, err error)
Select chooses an item based on the Smooth Weighted Round Robin algorithm. It returns the selected item or an error if no item is available or all are disabled.
func (*WeightedRoundRobinSelector[T]) TotalConfigWeight ¶
func (s *WeightedRoundRobinSelector[T]) TotalConfigWeight() int
TotalConfigWeight returns the sum of configured weights of all items.