balancer

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Policies added in v0.8.0

func Policies() []string

Policies returns the policies of all the registered balancers.

func Register added in v0.8.0

func Register(balancer Balancer)

Register registers the balancer.

Some balancers has been registered by default, as follow:

random
roundrobin
weight_random
weight_roundrobin
sourceip_hash
leastconn

If exists, override it.

func Unregister added in v0.8.0

func Unregister(policy string)

Unregister unregisters the balancer by the policy.

If not exist, do nothing.

Types

type Balancer

type Balancer interface {
	Policy() string
	Forwarder
}

Balancer does a balancer to forward the request to one of the backend endpoints by the specific policy.

var DefaultBalancer Balancer = roundrobin.NewBalancer("")

DefaultBalancer is the default balancer.

func Get added in v0.8.0

func Get(policy string) Balancer

Get returns the registered balancer by the policy.

If not exist, return nil.

func Gets added in v0.8.0

func Gets() []Balancer

Gets returns all the registered balancers.

type Forwarder

type Forwarder interface {
	Forward(ctx context.Context, req any, eps *loadbalancer.Static) (any, error)
}

Forwarder is used to forward the request to one of the backend endpoints.

Directories

Path Synopsis
Package consistenthash provides a balancer based on the consistent hash.
Package consistenthash provides a balancer based on the consistent hash.
Package leastconn provides a balancer based on the least connections.
Package leastconn provides a balancer based on the least connections.
Package random provides a balancer based on the random.
Package random provides a balancer based on the random.
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.
Package roundrobin provides a balancer based on the roundrobin.
Package roundrobin provides a balancer based on the roundrobin.
Package sourceiphash provides a balancer based on the source-ip hash.
Package sourceiphash provides a balancer based on the source-ip hash.

Jump to

Keyboard shortcuts

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