Help us shape the future of Go! Take the 2026 Go Developer Survey

ratelimit

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ratelimit reads the quota a server reports in its response headers: the RateLimit and RateLimit-Policy fields of the IETF draft (draft-ietf-httpapi-ratelimit-headers, still a draft: its field names may change), and the RateLimit-Limit/-Remaining/-Reset and X-RateLimit-* headers servers sent before it. A client can show what is left and wait for the quota to come back instead of failing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Policy    string        // the draft's policy name, "" for the older headers
	Limit     int           // requests allowed in the window; -1 when unknown
	Remaining int           // requests left; -1 when unknown
	Reset     time.Duration // until the quota is back
	Window    time.Duration // the policy's window, when the server gave it
}

Info is the quota a response reported. A figure the server did not give is -1 (Limit, Remaining) or zero.

func Read

func Read(h http.Header, now time.Time) (Info, bool)

Read reads the quota from the headers of a response received at now; found is false when it reports none. With several policies the one with the least left is returned.

func (Info) Exhausted

func (i Info) Exhausted() bool

Exhausted says nothing is left and the server said when it comes back, so waiting makes sense.

func (Info) Values

func (i Info) Values() map[string]any

Values is the quota as a flow reads it (nodes.<step>.ratelimit and response.ratelimit): policy, limit, remaining, reset (a duration), and wait, which is reset when nothing is left and zero otherwise, so a delay can take it as it is.

Jump to

Keyboard shortcuts

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