Documentation
¶
Index ¶
Constants ¶
View Source
const ( DefaultTimeout = 10 * time.Second DefaultMaxIdleConnsPerHost = 100 // Larger pool for connection reuse; rebalancing handled by MaxConnLifetime DefaultIdleConnTimeout = 90 * time.Second // Keep idle connections longer; lifetime-based rotation handles freshness DefaultMaxConnLifetime = 60 * time.Second // Force connection refresh for load balancing to new pods MaxRetriesCap = 5 // Retries before pool reset; 97% success rate with 50% bad connections )
Default values for HTTP client configuration Optimized for K8s: MaxConnLifetime ensures rebalancing, so pool can be larger for better performance
Variables ¶
View Source
var ErrConnExpired = errors.New("connection expired")
ErrConnExpired is returned when a connection exceeds its max lifetime. This error is handled specially by retryTransport - it doesn't count as a retry attempt.
Functions ¶
func ProvideHTTPClient ¶
ProvideHTTPClient returns a provider function that creates an HTTP client from config Usage with fx:
fx.Provide(fx.Private, httpclient.ProvideHTTPClient("catalog-service"))
Types ¶
type ClientConfig ¶
type ClientConfig struct {
BaseURL string `mapstructure:"base-url"`
Timeout *time.Duration `mapstructure:"timeout"`
MaxIdleConnsPerHost *int `mapstructure:"max-idle-conns-per-host"`
IdleConnTimeout *time.Duration `mapstructure:"idle-conn-timeout"`
MaxConnLifetime *time.Duration `mapstructure:"max-conn-lifetime"`
}
ClientConfig holds configuration for an HTTP client loaded from config file yaml example:
clients:
catalog-service:
base-url: http://catalog-service:8080
timeout: 10s
max-idle-conns-per-host: 10
idle-conn-timeout: 10s
max-conn-lifetime: 60s
Omit timeout fields to use defaults. Set to 0 to disable.
Click to show internal directories.
Click to hide internal directories.