client

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 10 Imported by: 0

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

func ProvideHTTPClient(name string) func(*viper.Viper) (*http.Client, ClientConfig, error)

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.

Jump to

Keyboard shortcuts

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