lbapi

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepEqual

func DeepEqual(a, b Peer) (yes bool)

DeepEqual will be used in Balancer, and a Peer can bypass reflect.DeepEqual by implementing DeepEqualAware interface.

Types

type Balancer

type Balancer interface {
	BalancerLite
	Count() int
	Add(peers ...Peer)
	Remove(peer Peer)
	Clear()
}

Balancer represents a generic load balancer. For the real world, Balancer is a useful interface rather than BalancerLite.

type BalancerLite

type BalancerLite interface {
	// Next will return the next backend.
	//
	// For some ones like consistent-hashed balancer, Next needs
	// a factor as its param. It might be the requesting URL
	// typically.
	// For else, you can pass a lbapi.DummyFactor or just an
	// empty string as factor.
	Next(factor Factor) (next Peer, c Constrainable)
}

BalancerLite represents a generic load balancer.

type Constrainable

type Constrainable interface {
	CanConstrain(o interface{}) (yes bool)
	Check(o interface{}) (satisfied bool)
	Peer
}

Constrainable is an object who can be applied onto a factor ( BalancerLite.Next(factor) )

type DeepEqualAware

type DeepEqualAware interface {
	DeepEqual(b Peer) bool
}

DeepEqualAware could be concreted by a Peer so you could customize how to compare two peers, avoid reflect.DeepEqual bypass.

type Factor

type Factor interface {
	Factor() string
}

Factor is a factor parameter for BalancerLite.Next.

If you won't known what should be passed into BalancerLite.Next, send DummyFactor as it.

But when you are constructing a complex lb system or a multiple-level one such as a weighted versioning load balancer. Take a look at our version.New and version.VersioningBackendFactor.

type FactorComparable

type FactorComparable interface {
	Factor
	ConstrainedBy(constraints interface{}) (peer Peer, c Constrainable, satisfied bool)
}

FactorComparable is a composite interface which assembly Factor and constraint comparing.

type FactorHashable added in v0.3.1

type FactorHashable interface {
	Factor
	HashCode() uint32
}

FactorHashable is a composite interface which assembly Factor and hashing computer.

type FactorString

type FactorString string

FactorString is a string type, it implements Factor interface.

const DummyFactor FactorString = ""

DummyFactor will be used in someone like you does not known what on earth should be passed into BalancerLite.Next(factor).

func (FactorString) Factor

func (s FactorString) Factor() string

Factor function impl Factor interface

type Opt

type Opt func(balancer Balancer)

Opt is a type prototype for New Balancer

type Peer

type Peer interface {
	// String will return the main identity string of a peer.
	//
	// You would have to implement only this one func to plug
	// your object into the architecture created by
	// lbapi.Balancer
	String() string
}

Peer is a backend object, such as a host+port, a http/https url, or a constraint expression, and so on.

type Weighted

type Weighted interface {
	Weight() int
}

Weighted object

type WeightedConstrainable

type WeightedConstrainable interface {
	Constrainable
	Weighted
}

WeightedConstrainable is an object who can be applied onto a factor ( BalancerLite.Next(factor) )

type WeightedPeer

type WeightedPeer interface {
	Peer
	Weighted
}

WeightedPeer is a Peer with Weight property.

Jump to

Keyboard shortcuts

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