utils

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoWithRetry

func DoWithRetry(ctx context.Context, client *http.Client, req *http.Request, maxRetries int, baseDelay time.Duration) (*http.Response, error)

DoWithRetry performs an HTTP request with exponential backoff retry

func DrainAndClose

func DrainAndClose(body io.ReadCloser)

DrainAndClose drains and closes a response body

func NewHTTPClient

func NewHTTPClient() *http.Client

NewHTTPClient creates a new HTTP client with standard configuration

func NewHTTPClientWithConfig

func NewHTTPClientWithConfig(cfg HTTPClientConfig) *http.Client

NewHTTPClientWithConfig creates a new HTTP client with custom configuration

func NewRequestWithJSON

func NewRequestWithJSON(ctx context.Context, method, url string, body []byte) (*http.Request, error)

NewRequestWithJSON creates a new request with JSON body

func ReadResponseBody

func ReadResponseBody(resp *http.Response, maxSize int64) ([]byte, error)

ReadResponseBody reads and returns the response body, limiting size

Types

type HTTPClientConfig

type HTTPClientConfig struct {
	Timeout        time.Duration
	MaxRetries     int
	RetryBaseDelay time.Duration
	Debug          bool
	ConnectTimeout time.Duration
}

HTTPClientConfig configures the HTTP client behavior

func DefaultHTTPConfig

func DefaultHTTPConfig() HTTPClientConfig

DefaultHTTPConfig returns the default HTTP client configuration

Jump to

Keyboard shortcuts

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