httpx

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package httpx provides a small rate-limited, retrying HTTP client shared by the source-forge and target-Forgejo API clients.

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 rate-limited HTTP client that transparently retries on HTTP 429 and 5xx responses, honoring the Retry-After header when present.

func New

func New(ratePerMinute int, log zerolog.Logger, opts ...Option) *Client

New builds a Client limited to ratePerMinute requests per minute. A ratePerMinute of zero or below disables rate limiting.

func (*Client) Do

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

Do sends req, blocking on the rate limiter first and retrying transient failures. The caller owns closing the returned body.

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, url string, headers map[string]string, out any) (int, error)

GetJSON performs a GET request and decodes the JSON body into out. It returns the HTTP status code, which is set even when a non-2xx status yields an error.

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, url string, headers map[string]string, body, out any) (int, error)

PostJSON performs a POST request with a JSON body and optionally decodes the JSON response into out. It returns the HTTP status code.

type Option

type Option func(*Client)

Option configures a Client.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient overrides the underlying *http.Client.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries overrides the default retry count.

Jump to

Keyboard shortcuts

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