httpclient

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 18 Imported by: 0

README

HTTP Client Module Architecture

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectQueryParams added in v0.0.7

func InjectQueryParams(rawURL string, queryParams map[string]string) string

func NewHTTPClient

func NewHTTPClient(baseURL string, config ClientConfig, fallbackFn func(error) error) *http.Client

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

func NewTracingHTTPClient(timeout time.Duration) *http.Client

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 DownloadFileResponse struct {
	Filename          string
	AdditionalDetails map[string]string
}

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

func (*TracingRoundTripper) RoundTrip added in v0.0.12

func (t *TracingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper and adds trace_id header propagation

Jump to

Keyboard shortcuts

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