connection

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CertPinner added in v1.3.8

type CertPinner interface {
	VerifyPeerCertificate(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error
}

CertPinner defines the interface for certificate pinning

type Config

type Config struct {
	MaxIdleConns        int
	MaxIdleConnsPerHost int
	MaxConnsPerHost     int
	MaxTotalConns       int

	DialTimeout           time.Duration
	KeepAlive             time.Duration
	TLSHandshakeTimeout   time.Duration
	ResponseHeaderTimeout time.Duration
	IdleConnTimeout       time.Duration
	ExpectContinueTimeout time.Duration

	TLSConfig          *tls.Config
	MinTLSVersion      uint16
	MaxTLSVersion      uint16
	InsecureSkipVerify bool

	EnableHTTP2 bool
	ProxyURL    string

	// System proxy configuration
	EnableSystemProxy bool // Automatically detect and use system proxy settings

	AllowPrivateIPs bool

	DisableCompression bool
	DisableKeepAlives  bool
	ForceAttemptHTTP2  bool

	CookieJar http.CookieJar

	// DNS configuration
	EnableDoH   bool          // Enable DNS-over-HTTPS
	DoHCacheTTL time.Duration // DoH cache TTL

	// Certificate pinning
	CertPinner CertPinner
}

Config defines connection pool configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns optimized default configuration

type HostStats

type HostStats struct {
	Host           string
	ActiveConns    int64
	IdleConns      int64
	TotalConns     int64
	FailedConns    int64
	LastUsed       int64 // Unix timestamp
	AverageLatency int64 // Nanoseconds
}

HostStats tracks per-host connection statistics

type Metrics

type Metrics struct {
	ActiveConnections   int64
	TotalConnections    int64
	RejectedConnections int64
	ConnectionHitRate   float64
	LastUpdate          int64
}

Metrics provides connection pool performance metrics

type PoolManager

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

PoolManager provides intelligent connection pool management with monitoring

func NewPoolManager

func NewPoolManager(config *Config) (*PoolManager, error)

NewPoolManager creates a new connection pool manager

func (*PoolManager) ClearHostStats added in v1.3.8

func (pm *PoolManager) ClearHostStats()

ClearHostStats clears all per-host connection statistics. This releases memory held by the hostConns map. Useful for long-running applications to periodically reset statistics. Thread-safe: can be called concurrently with other operations.

func (*PoolManager) Close

func (pm *PoolManager) Close() error

func (*PoolManager) GetHostStatsCount added in v1.3.8

func (pm *PoolManager) GetHostStatsCount() int

GetHostStatsCount returns the number of hosts currently being tracked. Useful for monitoring memory usage in production environments.

func (*PoolManager) GetMetrics

func (pm *PoolManager) GetMetrics() Metrics

func (*PoolManager) GetTransport

func (pm *PoolManager) GetTransport() *http.Transport

func (*PoolManager) IsHealthy

func (pm *PoolManager) IsHealthy() bool

Jump to

Keyboard shortcuts

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