Documentation ¶
Overview ¶
Package proxy is middleware that proxies requests.
Package proxy is middleware that proxies requests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterPolicy ¶
RegisterPolicy adds a custom policy to the proxy.
Types ¶
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 Options ¶
type Options struct {
Ecs []*net.IPNet // EDNS0 CLIENT SUBNET address (v4/v6) to add in CIDR notaton.
}
Options ...
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 Proxy ¶
type Proxy struct { Next middleware.Handler Client Client Upstreams []Upstream }
Proxy represents a middleware instance that can proxy requests.
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 ReverseProxy ¶
ReverseProxy is a basic reverse proxy
func (ReverseProxy) ServeDNS ¶
func (p ReverseProxy) ServeDNS(w dns.ResponseWriter, r *dns.Msg, extra []dns.RR) error
ServeDNS implements the middleware.Handler interface.
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 Upstream ¶
type Upstream interface { // The domain name this upstream host should be routed on. From() string // Selects an upstream host to be routed to. Select() *UpstreamHost // Checks if subpdomain is not an ignored. IsAllowedPath(string) bool // Options returns the options set for this upstream Options() Options }
Upstream manages a pool of proxy upstream hosts. Select should return a suitable upstream host, or nil if no such hosts are available.
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 Fails int32 FailTimeout time.Duration Unhealthy bool CheckDown UpstreamHostDownFunc WithoutPathPrefix string }
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.