proxyx

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package proxyx is a small reverse-proxy engine for an edge service: it builds an httputil.ReverseProxy to a single upstream that strips a leading API-version segment, forwards X-Forwarded-* headers, and maps upstream failures to clean gateway status codes. It's a leaf library (stdlib only) so any service can compose it — a gateway pairs it with its own routing table.

API versioning is handled at the edge: the public path is versioned (/v1/auth/login) and the proxy strips the leading /v{N} before forwarding, so version-agnostic upstreams receive the unversioned path (/auth/login). New versions become new upstream entries; no upstream has to learn about versions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(target *url.URL, transport http.RoundTripper) *httputil.ReverseProxy

New builds a reverse proxy to target. It strips a leading /v{N} version segment before forwarding (so a version-agnostic upstream receives the unversioned path), sets X-Forwarded-* so the upstream sees the real client, and routes through transport. The ErrorHandler maps a timed-out upstream to 504 Gateway Timeout and any other dial/transport failure to 502 Bad Gateway, so a flaky backend never surfaces as a naked dropped connection. Uses the Rewrite hook (not the deprecated Director).

func StripVersion

func StripVersion(path string) string

StripVersion removes a leading /v{N} segment from path: "/v1/auth/login" → "/auth/login", "/v2" → "/". A first segment that isn't a version ("/auth/login", "/version/x") is returned unchanged, so unversioned routes pass through untouched.

func Transport

func Transport(responseHeader time.Duration) *http.Transport

Transport returns a tuned upstream HTTP transport shared across proxies. It bounds each stage of an upstream call — dial, TLS handshake, waiting for response headers — and pools idle connections generously (the default MaxIdleConnsPerHost of 2 throttles a busy edge). A non-positive responseHeader disables that particular cap.

Types

This section is empty.

Jump to

Keyboard shortcuts

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