httpkit

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a generic HTTP client with common functionality

func NewClient

func NewClient(opts *Options) (*Client, error)

NewClient creates a new generic HTTP client

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do performs an HTTP request

func (*Client) DoRequestWithRetry

func (c *Client) DoRequestWithRetry(ctx context.Context, req *http.Request, retryOpts *RetryOptions) (*http.Response, error)

DoRequestWithRetry performs an HTTP request with retry logic

func (*Client) GetBaseURL

func (c *Client) GetBaseURL() string

GetBaseURL returns the base URL

func (*Client) GetHTTPClient

func (c *Client) GetHTTPClient() *http.Client

GetHTTPClient returns the underlying http.Client

func (*Client) InjectTraceContext

func (c *Client) InjectTraceContext(ctx context.Context, req *http.Request)

InjectTraceContext injects OpenTelemetry trace context into request headers

type Options

type Options struct {
	BaseURL            string
	Timeout            time.Duration
	UserAgent          string
	Transport          http.RoundTripper
	TLSCACertFile      string // For verifying server certificate
	TLSClientCert      string // Client certificate file for mTLS
	TLSClientKey       string // Client private key file for mTLS
	TLSServerName      string // Server name for TLS verification
	InsecureSkipVerify bool   // Skip TLS certificate verification (not recommended)
}

Options for creating a new Client

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns default options

func (*Options) Validate

func (o *Options) Validate() error

Validate validates the options

type RetryOptions

type RetryOptions struct {
	MaxRetries           int
	RetryDelay           time.Duration
	MaxRetryDelay        time.Duration
	BackoffMultiplier    float64
	RetryableStatusCodes []int
}

RetryOptions configuration for retry logic

func DefaultRetryOptions

func DefaultRetryOptions() *RetryOptions

DefaultRetryOptions returns default retry options

func (*RetryOptions) CalculateRetryDelay

func (r *RetryOptions) CalculateRetryDelay(attempt int) time.Duration

CalculateRetryDelay calculates the delay for the next retry attempt using exponential backoff

func (*RetryOptions) IsRetryableError

func (r *RetryOptions) IsRetryableError(err error, statusCode int) bool

IsRetryableError checks if an error should trigger a retry

Jump to

Keyboard shortcuts

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