ratelimited

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

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