reverseproxy

package
v0.0.0-...-744ddd9 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package reverseproxy provides an HTTP/HTTPS reverse proxy with request logging and statistics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeaderRule

type HeaderRule struct {
	Name   string
	Value  string
	Remove bool
}

HeaderRule defines a header to inject or strip.

type Options

type Options struct {
	ListenAddr  string
	BackendURL  string
	Headers     []HeaderRule
	Timeout     time.Duration
	SkipVerify  bool
	LogRequests bool
	OnRequest   func(RequestLog)
}

Options configures the reverse proxy.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns sensible defaults.

type Proxy

type Proxy struct {
	Stats *Statistics
	// contains filtered or unexported fields
}

Proxy is an HTTP reverse proxy with request logging.

func NewProxy

func NewProxy(opts Options) (*Proxy, error)

NewProxy creates a new reverse proxy.

func (*Proxy) BackendURL

func (p *Proxy) BackendURL() *url.URL

BackendURL returns the parsed backend URL.

func (*Proxy) ListenAddr

func (p *Proxy) ListenAddr() string

ListenAddr returns the configured listen address.

func (*Proxy) Run

func (p *Proxy) Run(ctx context.Context) error

Run starts the proxy and blocks until the context is cancelled.

type RequestLog

type RequestLog struct {
	Timestamp  time.Time
	Method     string
	Path       string
	StatusCode int
	Latency    time.Duration
	ClientAddr string
	BytesSent  int64
	Error      error
}

RequestLog represents a single proxied request.

type Statistics

type Statistics struct {
	TotalReqs    int
	SuccessReqs  int
	FailedReqs   int
	BytesSent    int64
	MinLatency   time.Duration
	MaxLatency   time.Duration
	AvgLatency   time.Duration
	MedianLat    time.Duration
	P95Latency   time.Duration
	P99Latency   time.Duration
	StatusCounts map[int]int
	MethodCounts map[string]int
	StartTime    time.Time
	// contains filtered or unexported fields
}

Statistics holds aggregate proxy statistics.

func NewStatistics

func NewStatistics() *Statistics

NewStatistics creates an initialized Statistics.

func (*Statistics) Calculate

func (s *Statistics) Calculate()

Calculate computes aggregate statistics.

func (*Statistics) Format

func (s *Statistics) Format() string

Format returns a human-readable statistics summary.

func (*Statistics) Record

func (s *Statistics) Record(log RequestLog)

Record adds a request log entry.

func (*Statistics) Snapshot

func (s *Statistics) Snapshot() Statistics

Snapshot returns a copy for safe reading.

Jump to

Keyboard shortcuts

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