Help us shape the future of Go! Take the 2026 Go Developer Survey

proxy

package
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 16 Imported by: 0

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

type Balancer interface {
	Next(*zinc.Context) (*Target, error)
}

Balancer selects an upstream for each request.

func NewRandomBalancer

func NewRandomBalancer(targets []*Target) Balancer

NewRandomBalancer returns a concurrency-safe pseudo-random balancer.

func NewRoundRobinBalancer

func NewRoundRobinBalancer(targets []*Target) Balancer

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.

type Target

type Target struct {
	Name string
	URL  *url.URL
}

Target names an absolute upstream URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL