ratelimit

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 7 Imported by: ? 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 ratelimit caps the requests the relay makes through one connection. The cap is one counter per connection, shared by everything that uses it (the listings and reads of the polling source): a request over the cap is not made, it fails with ErrRateLimited and the caller retries at its next poll.

Index

Constants

This section is empty.

Variables

View Source
var ErrRateLimited = errors.New("request rate limit reached")

ErrRateLimited is the cause of a request that was not made because the limit of its connection was reached.

Functions

func Wrap

func Wrap(connection string, perSecond int, store objectstore.ObjectStore, lister objectstore.Lister,
	now func() time.Time,
) (*Store, *Lister)

Wrap puts the store, and the lister when there is one, behind a limit of perSecond requests per second on the connection. The lister it returns is nil when lister is nil.

Types

type Lister

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

Lister is a lister that shares the limit of a Store.

func (*Lister) CanHead

func (l *Lister) CanHead() bool

CanHead implements objectstore.Lister: whether the lister behind the limit can describe one key. It makes no request.

func (*Lister) Head

func (l *Lister) Head(ctx context.Context, key string) (objectstore.ListEntry, error)

Head implements objectstore.Lister. A store that cannot answer is asked nothing and costs no request of the limit.

func (*Lister) List

List implements objectstore.Lister.

type Store

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

Store is an object store whose requests, and the ones of its lister, go through one limit.

func (*Store) Close

func (s *Store) Close() error

Close closes the store behind the limit.

func (*Store) CloseIdleConnections

func (s *Store) CloseIdleConnections()

CloseIdleConnections passes the call on to the store behind the limit.

func (*Store) Connection

func (s *Store) Connection() string

Connection is the name of the connection the limit belongs to.

func (*Store) Get

Get implements objectstore.ObjectStore.

func (*Store) PerSecond

func (s *Store) PerSecond() int

PerSecond is the limit, in requests per second.

func (*Store) Refused

func (s *Store) Refused() uint64

Refused is the number of requests of the connection that were refused because the limit was reached, since the store was made.

Jump to

Keyboard shortcuts

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