Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // SupportedPolicies is the collection of policies registered SupportedPolicies = make(map[string]func() Policy) )
Functions ¶
func RegisterPolicy ¶
RegisterPolicy adds a custom policy to the proxy.
Types ¶
type HealthCheck ¶
type HealthCheck struct { Hosts HostPool Policy Policy Spray Policy FailTimeout time.Duration MaxFails int32 Future time.Duration Path string Port string Interval time.Duration // contains filtered or unexported fields }
HealthCheck is used for performing healthcheck on a collection of upstream hosts and select one based on the policy.
func (*HealthCheck) Select ¶
func (u *HealthCheck) Select() *UpstreamHost
Select selects an upstream host based on the policy and the healthcheck result.
func (*HealthCheck) Stop ¶
func (u *HealthCheck) Stop() error
Stop sends a signal to all goroutines started by this staticUpstream to exit and waits for them to finish before returning.
type LeastConn ¶
type LeastConn struct{}
LeastConn is a policy that selects the host with the least connections.
func (*LeastConn) Select ¶
func (r *LeastConn) Select(pool HostPool) *UpstreamHost
Select selects the up host with the least number of connections in the pool. If more than one host has the same least number of connections, one of the hosts is chosen at random.
type Policy ¶
type Policy interface {
Select(pool HostPool) *UpstreamHost
}
Policy decides how a host will be selected from a pool. When all hosts are unhealthy, it is assumed the healthchecking failed. In this case each policy will *randomly* return a host from the pool to prevent no traffic to go through at all.
type Random ¶
type Random struct{}
Random is a policy that selects up hosts from a pool at random.
func (*Random) Select ¶
func (r *Random) Select(pool HostPool) *UpstreamHost
Select selects an up host at random from the specified pool.
type RoundRobin ¶
type RoundRobin struct {
Robin uint32
}
RoundRobin is a policy that selects hosts based on round robin ordering.
func (*RoundRobin) Select ¶
func (r *RoundRobin) Select(pool HostPool) *UpstreamHost
Select selects an up host from the pool using a round robin ordering scheme.
type Spray ¶
type Spray struct{}
Spray is a policy that selects a host from a pool at random. This should be used as a last ditch attempt to get a host when all hosts are reporting unhealthy.
func (*Spray) Select ¶
func (r *Spray) Select(pool HostPool) *UpstreamHost
Select selects an up host at random from the specified pool.
type UpstreamHost ¶
type UpstreamHost struct { Conns int64 // must be first field to be 64-bit aligned on 32-bit systems Name string // IP address (and port) of this upstream host Network string // Network (tcp, unix, etc) of the host, default "" is "tcp" Fails int32 FailTimeout time.Duration OkUntil time.Time CheckDown UpstreamHostDownFunc CheckURL string WithoutPathPrefix string Checking bool CheckMu sync.Mutex }
UpstreamHost represents a single proxy upstream
func (*UpstreamHost) Down ¶
func (uh *UpstreamHost) Down() bool
Down checks whether the upstream host is down or not. Down will try to use uh.CheckDown first, and will fall back to some default criteria if necessary.
type UpstreamHostDownFunc ¶
type UpstreamHostDownFunc func(*UpstreamHost) bool
UpstreamHostDownFunc can be used to customize how Down behaves.