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 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 NewConsistent ¶
NewConsistent create new Consistent balancer
func NewLeastLoad ¶
NewLeastLoad create new LeastLoad balancer
func NewRoundRobin ¶
NewRoundRobin create new RoundRobin balancer
type Bounded ¶
type Bounded struct {
// contains filtered or unexported fields
}
Bounded refers to consistent hash with bounded
type Consistent ¶
type Consistent struct {
// 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 ¶
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 P2C ¶
P2C refer to the power of 2 random choice
type Random ¶
Random will randomly select a http server from the server
type RoundRobin ¶
RoundRobin will select the server in turn from the server to proxy
func (*RoundRobin) Balance ¶
func (r *RoundRobin) Balance(_ string) (string, error)
Balance selects a suitable host according
func (*RoundRobin) Remove ¶
func (r *RoundRobin) Remove(host string)
Remove new host from the balancer