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 ¶
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.
type Proxy ¶
type Proxy struct {
Stats *Statistics
// contains filtered or unexported fields
}
Proxy is an HTTP reverse proxy with request logging.
func (*Proxy) BackendURL ¶
BackendURL returns the parsed backend URL.
func (*Proxy) ListenAddr ¶
ListenAddr returns the configured listen address.
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.