balancer

package
Version: v0.0.0-...-f5c7215 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 5 Imported by: 2

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
t or T : Toggle theme light dark auto
y or Y : Canonical URL