httpclient

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package httpclient provides a shared, rate-limited, concurrent HTTP client used across all SwaggerVu modules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEach

func ForEach[T any](ctx context.Context, concurrency int, items []T, fn func(ctx context.Context, item T))

ForEach runs fn over items using up to `concurrency` workers. It stops early if ctx is cancelled.

Types

type Client

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

Client is a thin wrapper around http.Client adding a global rate limiter.

func New

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

New builds a Client from Options.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, url string, body io.Reader) (*Response, error)

Do performs a request honoring the rate limiter and default headers.

func (*Client) DoWithHeaders

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

DoWithHeaders performs a request, applying per-request headers on top of the client defaults (used to send the generated Content-Type and header params).

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) (*Response, error)

Get is a convenience wrapper for GET.

type Options

type Options struct {
	Timeout        time.Duration
	Insecure       bool
	Proxy          string // http(s):// proxy URL
	UserAgent      string
	RandomizeUA    bool
	RatePerSecond  float64 // 0 = unlimited
	Headers        map[string]string
	FollowRedirect bool
}

Options configures a Client.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns sensible defaults.

type Response

type Response struct {
	URL         string
	Status      int
	Body        []byte
	ContentType string
	Header      http.Header
}

Response is a lightweight captured response.

func (*Response) BodyString

func (r *Response) BodyString() string

BodyString returns the response body as a string.

func (*Response) IsJSON

func (r *Response) IsJSON() bool

IsJSON reports whether the content type looks like JSON.

Jump to

Keyboard shortcuts

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