reverseproxy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package reverseproxy provides reverse proxy functionality with automatic TLS via ACME.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// Host is the hostname/pattern to match (e.g., "api.example.com" or "*.example.com")
	Host string `yaml:"host"`
	// Target is the backend URL (e.g., "http://localhost:3000")
	Target string `yaml:"target"`
	// StripPrefix removes a path prefix before forwarding
	StripPrefix string `yaml:"stripPrefix,omitempty"`
	// AddHeaders are headers to add to proxied requests
	AddHeaders map[string]string `yaml:"addHeaders,omitempty"`
	// HealthCheck is the health check path
	HealthCheck string `yaml:"healthCheck,omitempty"`
}

Backend represents a backend server configuration.

type Config

type Config struct {
	// HTTPPort is the port for HTTP traffic (default: 80)
	HTTPPort int
	// HTTPSPort is the port for HTTPS traffic (default: 443)
	HTTPSPort int
	// Backends is the list of backend configurations
	Backends []Backend
	// ACMEEmail is the email for Let's Encrypt registration
	ACMEEmail string
	// ACMECacheDir is the directory to cache certificates
	ACMECacheDir string
	// ACMEStaging uses Let's Encrypt staging environment (for testing)
	ACMEStaging bool
	// Capturer is the traffic capturer (optional)
	Capturer *capture.Capturer
	// Verbose enables verbose logging
	Verbose bool
	// RedirectHTTP redirects HTTP to HTTPS
	RedirectHTTP bool
}

Config holds reverse proxy configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default reverse proxy configuration.

type ReverseProxy

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

ReverseProxy represents a reverse proxy server with ACME support.

func New

func New(cfg *Config) (*ReverseProxy, error)

New creates a new reverse proxy with the given configuration.

func (*ReverseProxy) HealthCheck

func (rp *ReverseProxy) HealthCheck(ctx context.Context) map[string]bool

HealthCheck performs health checks on all backends.

func (*ReverseProxy) ListenAndServe

func (rp *ReverseProxy) ListenAndServe() error

ListenAndServe starts the reverse proxy server.

func (*ReverseProxy) ServeHTTP

func (rp *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

func (*ReverseProxy) TLSConfig

func (rp *ReverseProxy) TLSConfig() *tls.Config

TLSConfig returns the TLS configuration with ACME support.

Jump to

Keyboard shortcuts

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