httpclient

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 8 Imported by: 0

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 represents a generic HTTP client with retry logic

func NewClient

func NewClient(config Config) *Client

NewClient creates a new HTTP client with the given configuration

func (*Client) Do

func (c *Client) Do(ctx context.Context, req Request) (*Response, error)

Do executes an HTTP request with retry logic

func (*Client) Request

func (c *Client) Request(ctx context.Context, verb, url string, body io.Reader, headers map[string]string) (*Response, error)

Request performs an HTTP request with the specified verb

type Config

type Config struct {
	// Timeout is the HTTP client timeout for requests
	Timeout time.Duration

	// MaxRetries is the maximum number of retry attempts for failed requests
	MaxRetries int

	// RetryDelay is the delay between retry attempts
	RetryDelay time.Duration

	// RetryBackoff enables exponential backoff for retries
	RetryBackoff bool
}

Config holds the configuration for the HTTP client

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults

type Request

type Request struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    io.Reader
}

Request represents an HTTP request configuration

type Response

type Response struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
}

Response represents an HTTP response

type RetryableError

type RetryableError struct {
	StatusCode int
	Message    string
}

RetryableError represents an error that can be retried

func (*RetryableError) Error

func (e *RetryableError) Error() string

Jump to

Keyboard shortcuts

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