Documentation ¶
Index ¶
Constants ¶
const ( IPHashBalancer = "ip-hash" ConsistentHashBalancer = "consistent-hash" P2CBalancer = "p2c" RandomBalancer = "random" R2Balancer = "round-robin" )
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 NewRoundRobin ¶
NewRoundRobin create new RoundRobin balancer
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 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