Documentation ¶
Index ¶
Constants ¶
const ( R2Balancer = "round-robin" RandomBalancer = "random" IPHashBalancer = "ip-hash" ConsistentHashBalancer = "consistent-hash" LeastLoadBalancer = "least-load" )
Variables ¶
var ( ErrNoHost = errors.New("no host") ErrAlgoNotSupported = errors.New("algorithm not supported") )
Functions ¶
This section is empty.
Types ¶
type Balancer ¶
type Balancer interface { Add(string) Remove(string) Balance(string) (string, error) Inc(string) Done(string) }
Balancer interface is the load balancer for the reverse proxy
func NewConsistent ¶
NewConsistent create new Consistent balancer
func NewLeastLoad ¶
NewLeastLoad create new LeastLoad balancer
func NewRoundRobin ¶
NewRoundRobin create new RoundRobin balancer
type BaseBalancer ¶
func (*BaseBalancer) Balance ¶
func (b *BaseBalancer) Balance(key string) (string, error)
Balance selects a suitable host according to the key value
func (*BaseBalancer) Done ¶
func (b *BaseBalancer) Done(_ string)
Done refers to the number of connections to the server `-1`
func (*BaseBalancer) Inc ¶
func (b *BaseBalancer) Inc(_ string)
Inc refers to the number of connections to the server `+1`
func (*BaseBalancer) Remove ¶
func (b *BaseBalancer) Remove(host string)
Remove new host from the balancer
type Consistent ¶
type Consistent struct { BaseBalancer // contains filtered or unexported fields }
Consistent refers to consistent hash
func (*Consistent) Balance ¶
func (c *Consistent) Balance(key string) (string, error)
Balance selects a suitable host according to the key value
func (*Consistent) Done ¶
func (b *Consistent) Done(host string)
Done refers to the number of connections to the server `-1`
func (*Consistent) Inc ¶
func (b *Consistent) Inc(host string)
Inc refers to the number of connections to the server `+1`
func (*Consistent) Remove ¶
func (c *Consistent) Remove(host string)
Remove new host from the balancer
type IPHash ¶
type IPHash struct {
BaseBalancer
}
IPHash will choose a host based on the client's IP address
type LeastLoad ¶
LeastLoad will choose a host based on the least load host
type Random ¶
type Random struct { BaseBalancer // contains filtered or unexported fields }
Random will randomly select a http server from the server
type RoundRobin ¶
type RoundRobin struct { BaseBalancer // contains filtered or unexported fields }
RoundRobin will select the server in turn from the server to proxy