Documentation
¶
Overview ¶
Package proxy forwards requests to upstream servers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(configs ...Config) zinc.Middleware
New forwards matching requests to an upstream through an httputil.ReverseProxy and ends the chain there. Custom directors and transports run with the same trust as application code.
Types ¶
type Balancer ¶
Balancer selects an upstream for each request.
func NewRandomBalancer ¶
NewRandomBalancer returns a concurrency-safe pseudo-random balancer.
func NewRoundRobinBalancer ¶
NewRoundRobinBalancer returns a concurrency-safe round-robin balancer.
type Config ¶
type Config struct {
// Target is one absolute upstream URL.
Target string
Targets []*Target
Balancer Balancer
// Director runs after hop-by-hop and inbound forwarding headers are removed.
Director func(*http.Request)
ModifyResponse func(*http.Response) error
ErrorHandler func(http.ResponseWriter, *http.Request, error)
Retries int
RetryFilter func(*zinc.Context, error) bool
// Rewrite maps an upstream path, after the target's own path is added,
// to the path to send instead. A path ending in "*" matches a prefix,
// and a "*" in the target is replaced by the rest of the path. When
// several rules match, an exact rule wins over every "*" rule, and among
// "*" rules the longest prefix wins. The order is fixed when New runs.
Rewrite map[string]string
// RegexRewrite holds regular-expression path rules, tried when no
// Rewrite rule matches; the target may use $1-style references. A map
// has no order, so New puts the rules in one: the longest pattern
// source is tried first, then patterns in lexical order, and the first
// match wins. New panics when two rules have the same pattern source.
RegexRewrite map[*regexp.Regexp]string
Transport http.RoundTripper
}
Config controls upstream selection, rewriting, retries, and transport. One of Target, Targets, or Balancer is required.
Click to show internal directories.
Click to hide internal directories.