Documentation
¶
Overview ¶
Package httpclient provides an HTTP client with retry, circuit breaker, and mTLS/TLS support. Built on top of gojek/heimdall with Hystrix circuit breaker and exponential backoff.
Reference: https://github.com/gojek/heimdall
Index ¶
- func InjectQueryParams(rawURL string, queryParams map[string]string) string
- func NewHTTPClient(baseURL string, config ClientConfig, fallbackFn func(error) error) *http.Client
- func NewHystixClient(baseURL string, config ClientConfig, fallbackFn func(error) error) *circuitClient
- func NewTracingHTTPClient(timeout time.Duration) *http.Client
- type Client
- type ClientConfig
- type DownloadFileResponse
- type TLSClientConfig
- type TracingRoundTripper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectQueryParams ¶ added in v0.0.7
func NewHTTPClient ¶
NewHTTPClient wraps a Hystrix client in a standard *http.Client.
func NewHystixClient ¶
func NewHystixClient(baseURL string, config ClientConfig, fallbackFn func(error) error) *circuitClient
NewHystixClient creates a Heimdall Hystrix client with retries, backoff, and optional TLS/mTLS.
func NewTracingHTTPClient ¶ added in v0.0.12
NewTracingHTTPClient creates a simple *http.Client that automatically propagates trace_id from request context to X-Trace-ID header. Use this for simple HTTP clients without circuit breaker or retry logic.
Types ¶
type Client ¶
type Client interface {
Get(path string, queryParams map[string]string, response any) error
Post(path string, data any, response any) error
Put(path string, data any, response any) error
Delete(path string) error
WithOverrideBaseURL(url string) Client
DoRequest(method, path string, queryParams map[string]string, requestBody any, responseBody any, headers map[string]string) error
DownloadToFile(method, path string, queryParams map[string]string, body any, outputDir string, headers []string) (*DownloadFileResponse, error)
}
Client defines a high-level HTTP client interface with common methods.
type ClientConfig ¶
type ClientConfig struct {
Timeout time.Duration
RetryCount int
BackoffInitial time.Duration
BackoffMax time.Duration
CircuitBreakerCommand string
CircuitBreakerTimeout time.Duration
MaxConcurrentRequests int
ErrorPercentThreshold int
SleepWindow int
RequestVolumeThreshold int
TLSClientConfig TLSClientConfig
}
ClientConfig defines configuration for retries, backoff, and circuit breaker.
func DefaultConfig ¶
func DefaultConfig() ClientConfig
DefaultConfig returns a sensible default configuration.
type DownloadFileResponse ¶ added in v0.0.7
type TLSClientConfig ¶ added in v0.0.7
type TLSClientConfig struct {
// TLS/server verification
SkipTLSVerify bool
CACertPaths []string // Custom CA roots for server verification
// mTLS: client authentication
ClientCertPath string
ClientKeyPath string
// In-memory PEM
ClientCertPEM string
ClientKeyPEM string
// PKCS#12 (.p12 / .pfx)
ClientP12Path string
ClientP12Value string
ClientP12Password string
}
TLSClientConfig supports TLS and mTLS configurations.
type TracingRoundTripper ¶ added in v0.0.12
type TracingRoundTripper struct {
Base http.RoundTripper
}
TracingRoundTripper wraps an http.RoundTripper and propagates trace_id from context