lb

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepEqual

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

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

Types

type Balancer

type Balancer interface {
	Count() int
	All() []Endpoint
	Add(peers ...Endpoint)
	Remove(peer Endpoint)
	Clear()
	// contains filtered or unexported methods
}

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

func New

func New(opts ...Opt) Balancer

New make a new load-balancer instance with Round-Robin

type Constrainable

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

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

type DeepEqualAware

type DeepEqualAware interface {
	DeepEqual(b Endpoint) bool
}

DeepEqualAware could be concreted by an Endpoint

type Endpoint

type Endpoint interface {
	// String will return the main identity string of a endpoint.
	String() string
}

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

type Factor

type Factor interface {
	Factor() string
}

Factor is a factor parameter for balancer.Next.

type FactorComparable

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

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

type FactorString

type FactorString string

FactorString is a string type, it implements Factor interface.

const DummyFactor FactorString = "robin"

DummyFactor will be used in someone like you does not known what on earth should be passed into balancer.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

Jump to

Keyboard shortcuts

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