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

proxy

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package proxy runs an embedded Caddy server that terminates TLS and routes requests by host name to upstream services.

Caddy keeps its state in process-global variables, so a process can run only one Proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// HTTPPort is the port for plain HTTP, which serves ACME challenges and
	// redirects to HTTPS.
	HTTPPort int
	// HTTPSPort is the port the proxy serves HTTPS on.
	HTTPSPort int
	// Email is the optional contact address for ACME certificates.
	Email string
	// StorageDir is where certificates are stored. Empty uses Caddy's default.
	StorageDir string
	// LogFile is the file Caddy logs to. Caddy rotates it itself. Empty
	// discards Caddy's logs.
	LogFile string
	// Cloudflare trusts requests from Cloudflare's edge to carry the client
	// IP in CF-Connecting-IP and X-Forwarded-* headers. Requests from other
	// addresses are unaffected.
	Cloudflare bool
}

Config configures a Proxy.

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy is an embedded reverse proxy.

func New

func New(cfg Config) *Proxy

New returns a Proxy that is not yet running. Apply starts it.

func (*Proxy) Apply

func (p *Proxy) Apply(routes []Route) error

Apply makes the proxy serve exactly routes, starting it if necessary. Certificates are obtained automatically for the route hosts. Apply does nothing if the resulting configuration is already loaded. It is safe for concurrent use.

func (*Proxy) Stop

func (p *Proxy) Stop() error

Stop shuts the proxy down. A later Apply starts it again.

type Route

type Route struct {
	// Host is the host name to match, such as "app.example.com".
	Host string
	// Upstream is the address to proxy to, as host:port.
	Upstream string
}

Route sends requests for a host name to an upstream.

Jump to

Keyboard shortcuts

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