ratelimited

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ratelimited provides a rate-limited HTTP client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(client *http.Client, limiter Limiter) *http.Client

NewClient creates a new HTTP client that calls limiter to apply a rate limit to requests. If client is nil, http.DefaultClient is used. If limiter is nil, no rate limiting is applied.

Types

type Limiter

type Limiter func(context.Context) error

Limiter is a function that is expected to wait until rate limiting conditions have been met. The implementation should return early if the provided context expires.

type Transport

type Transport struct {
	L    Limiter
	Base interface {
		Do(req *http.Request) (*http.Response, error)
	}
}

Transport is an http.RoundTripper that calls L to apply a rate limit to requests. If Transport is nil, http.DefaultTransport is used. If L is nil, no rate limiting is applied.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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