Documentation
¶
Index ¶
- Constants
- Variables
- type Balancer
- func Build(algorithm string, hosts []string) (Balancer, error)
- func NewBounded(hosts []string) Balancer
- func NewConsistent(hosts []string) Balancer
- func NewIPHash(hosts []string) Balancer
- func NewLeastLoad(hosts []string) Balancer
- func NewP2C(hosts []string) Balancer
- func NewRandom(hosts []string) Balancer
- func NewRoundRobin(hosts []string) Balancer
- type BaseBalancer
- type Bounded
- type Consistent
- type Factory
- type IPHash
- type LeastLoad
- type P2C
- type Random
- type RoundRobin
Constants ¶
const ( IPHashBalancer = "ip-hash" ConsistentHashBalancer = "consistent-hash" P2CBalancer = "p2c" RandomBalancer = "random" R2Balancer = "round-robin" LeastLoadBalancer = "least-load" BoundedBalancer = "bounded" )
const Salt = "%#!"
Variables ¶
var ( NoHostError = errors.New("no host") AlgorithmNotSupportedError = 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 NewBounded ¶ added in v0.2.0
NewBounded create new Bounded balancer
func NewConsistent ¶
NewConsistent create new Consistent balancer
func NewLeastLoad ¶ added in v0.2.0
NewLeastLoad create new LeastLoad balancer
func NewRoundRobin ¶
NewRoundRobin create new RoundRobin balancer
type BaseBalancer ¶ added in v0.2.1
func (*BaseBalancer) Add ¶ added in v0.2.1
func (b *BaseBalancer) Add(host string)
Add new host to the balancer
func (*BaseBalancer) Balance ¶ added in v0.2.1
func (b *BaseBalancer) Balance(key string) (string, error)
Balance selects a suitable host according
func (*BaseBalancer) Remove ¶ added in v0.2.1
func (b *BaseBalancer) Remove(host string)
Remove new host from the balancer
type Bounded ¶ added in v0.2.0
type Bounded struct {
// contains filtered or unexported fields
}
Bounded refers to consistent hash with bounded
func (*Bounded) Balance ¶ added in v0.2.0
Balance selects a suitable host according to the key value
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) Remove ¶
func (c *Consistent) Remove(host string)
Remove new host from the balancer
type Factory ¶
Factory is the factory that generates Balancer, and the factory design pattern is used here
type IPHash ¶
type IPHash struct {
BaseBalancer
}
IPHash will choose a host based on the client's IP address
type LeastLoad ¶ added in v0.2.0
LeastLoad will choose a host based on the least load host
func (*LeastLoad) Done ¶ added in v0.2.0
Done refers to the number of connections to the server `-1`
type P2C ¶
P2C refer to the power of 2 random choice
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