Documentation ¶
Overview ¶
Package loadbalancer provides some common functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoAvailableEndpoints = errors.New("no available endpoints")
ErrNoAvailableEndpoints is used to represents no available endpoints.
var None = new(Static)
None represents a static without endpoints.
var SortEndpoints func(Endpoints) = sortEndpoints
SortEndpoints is used to sort a set of the endpoints.
For the default implementation, sort them by the id from small to big.
Functions ¶
Types ¶
type AtomicStatic ¶ added in v0.9.0
type AtomicStatic struct {
// contains filtered or unexported fields
}
AtomicStatic is a atomic static discovery.
func NewAtomicStatic ¶ added in v0.9.0
func NewAtomicStatic(static *Static) *AtomicStatic
NewAtomicStatic a new atomic static.
func (*AtomicStatic) Discover ¶ added in v0.9.0
func (s *AtomicStatic) Discover() *Static
Discover implements the interface Discovery.
func (*AtomicStatic) Set ¶ added in v0.9.0
func (s *AtomicStatic) Set(new *Static)
Set sets the static to new.
func (*AtomicStatic) Swap ¶ added in v0.9.0
func (s *AtomicStatic) Swap(new *Static) (old *Static)
Swap swap the old static with the new.
type Discovery ¶ added in v0.8.0
type Discovery interface {
Discover() *Static
}
Discovery is used to discover the endpoints.
type DiscoveryFunc ¶ added in v0.8.0
type DiscoveryFunc func() *Static
DiscoveryFunc is a discovery function.
func (DiscoveryFunc) Discover ¶ added in v0.8.0
func (f DiscoveryFunc) Discover() *Static
Discover implements the interface Discovery.
type Endpoint ¶
type Endpoint interface { LoadBalancer ID() string }
Endpoint represents a backend endpoint.
type Endpoints ¶
type Endpoints []Endpoint
Endpoints represents a group of the endpoints.
func (Endpoints) Contains ¶
Contains reports whether the endpoints contains the endpoint indicated by the id.
type LoadBalancer ¶
LoadBalancer is a load balancer to serve the request.
type RetryError ¶ added in v0.7.0
RetryError represents a retry error.
func NewRetryError ¶ added in v0.7.0
func NewRetryError(retry bool, err error) RetryError
NewRetryError returns a new retry error, but returns nil instead if err is nil.
type Static ¶ added in v0.8.0
type Static struct{ Endpoints }
Static is used to wrap a set of endpoints.
func NewStaticWithCap ¶ added in v0.9.0
NewStaticWithCap returns a new static with the 0-len and n-cap endpoints.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package balancer provides a balancer interface and builder, which is used to forward the request to one of the backend endpoints by the specific policy.
|
Package balancer provides a balancer interface and builder, which is used to forward the request to one of the backend endpoints by the specific policy. |
consistenthash
Package consistenthash provides a balancer based on the consistent hash.
|
Package consistenthash provides a balancer based on the consistent hash. |
leastconn
Package leastconn provides a balancer based on the least connections.
|
Package leastconn provides a balancer based on the least connections. |
random
Package random provides a balancer based on the random.
|
Package random provides a balancer based on the random. |
retry
Package retry provides a retry balancer, which will retry the rest endpoints when failing to forward the request.
|
Package retry provides a retry balancer, which will retry the rest endpoints when failing to forward the request. |
roundrobin
Package roundrobin provides a balancer based on the roundrobin.
|
Package roundrobin provides a balancer based on the roundrobin. |
sourceiphash
Package sourceiphash provides a balancer based on the source-ip hash.
|
Package sourceiphash provides a balancer based on the source-ip hash. |
Package endpoint provides some auxiliary functions about endpoint.
|
Package endpoint provides some auxiliary functions about endpoint. |
Package forwarder provides a loadbalance forwarder.
|
Package forwarder provides a loadbalance forwarder. |
Package httpx provides some functions about http.
|
Package httpx provides some functions about http. |
internal
|
|