balancer

package
v0.0.0-...-ce8de81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 5 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package balancer provides a simple interface to create concrete balancer algorightms that can be used to choose an upstream

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyBackendList is used when the list of beckends is empty
	ErrEmptyBackendList = errors.New("can not elect backend, Backends empty")
	// ErrCannotElectBackend is used a backend cannot be elected
	ErrCannotElectBackend = errors.New("cant elect backend")
	// ErrUnsupportedAlgorithm is used when an unsupported algorithm is given
	ErrUnsupportedAlgorithm = errors.New("unsupported balancing algorithm")
)
View Source
var (
	// ErrZeroWeight is used when there a zero value weight was given
	ErrZeroWeight = errors.New("invalid backend, weight 0 given")
)

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	Elect(hosts []*Target) (*Target, error)
}

Balancer holds the load balancer methods for many different algorithms

func New

func New(balance string) (Balancer, error)

New creates a new Balancer based on balancing strategy

type RoundrobinBalancer

type RoundrobinBalancer struct {
	// contains filtered or unexported fields
}

RoundrobinBalancer balancer

func NewRoundrobinBalancer

func NewRoundrobinBalancer() *RoundrobinBalancer

NewRoundrobinBalancer creates a new instance of Roundrobin

func (*RoundrobinBalancer) Elect

func (b *RoundrobinBalancer) Elect(hosts []*Target) (*Target, error)

Elect backend using roundrobin strategy

type Target

type Target struct {
	Target string
	Weight int
}

Target is an ip address/hostname with a port that identifies an instance of a backend service

type WeightBalancer

type WeightBalancer struct{}

WeightBalancer balancer

func NewWeightBalancer

func NewWeightBalancer() *WeightBalancer

NewWeightBalancer creates a new instance of WeightBalancer

func (*WeightBalancer) Elect

func (b *WeightBalancer) Elect(hosts []*Target) (*Target, error)

Elect backend using weight strategy

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL