limiter

package
v0.0.0-...-0265167 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitBackend

func LimitBackend(be backend.Backend, l Limiter) backend.Backend

LimitBackend wraps a Backend and applies rate limiting to Load() and Save() calls on the backend.

func WrapBackendConstructor

func WrapBackendConstructor[B backend.Backend, C any](constructor func(ctx context.Context, cfg C) (B, error)) func(ctx context.Context, cfg C, lim Limiter) (backend.Backend, error)

Types

type Limiter

type Limiter interface {
	// Upstream returns a rate limited reader that is intended to be used in
	// uploads.
	Upstream(r io.Reader) io.Reader

	// UpstreamWriter returns a rate limited writer that is intended to be used
	// in uploads.
	UpstreamWriter(w io.Writer) io.Writer

	// Downstream returns a rate limited reader that is intended to be used
	// for downloads.
	Downstream(r io.Reader) io.Reader

	// Downstream returns a rate limited reader that is intended to be used
	// for downloads.
	DownstreamWriter(r io.Writer) io.Writer

	// Transport returns an http.RoundTripper limited with the limiter.
	Transport(http.RoundTripper) http.RoundTripper
}

Limiter defines an interface that implementers can use to rate limit I/O according to some policy defined and configured by the implementer.

func NewStaticLimiter

func NewStaticLimiter(l Limits) Limiter

NewStaticLimiter constructs a Limiter with a fixed (static) upload and download rate cap

type Limits

type Limits struct {
	UploadKb   int
	DownloadKb int
}

Limits represents static upload and download limits. For both, zero means unlimited.

Jump to

Keyboard shortcuts

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