request

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package request defines and implements Limiter and Tagger for throttling [http.Request]s.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextTagger

type ContextTagger func(context.Context) (string, error)

ContextTagger is used together with NewRequestTaggerFromContextTagger to tag requests based on context values. This can help with rate-limiting requests by a role.

type Limiter

type Limiter interface {
	Rate() *rate.Rate
	Take(
		*http.Request,
	) (
		remaining float64,
		ok bool,
		err error,
	)
}

func NewLimiter

func NewLimiter(t Tagger, l rate.Limiter) (Limiter, error)

func NewStaticLimiter

func NewStaticLimiter(tag string, l rate.Limiter) (Limiter, error)

type Tagger

type Tagger func(*http.Request) (string, error)

Tagger associates tags to [http.Request]s in order to group related requests for a discriminating rate limiter. Requests with the same association tag will be tracked together by the Limiter.

func NewRequestTaggerFromContextTagger

func NewRequestTaggerFromContextTagger(t ContextTagger) Tagger

NewRequestTaggerFromContextTagger adapts a ContextTagger to a Tagger.

Directories

Path Synopsis
Package tagbycontext implements [request.Limiter] by extracting values from request context.Context.
Package tagbycontext implements [request.Limiter] by extracting values from request context.Context.
Package tagbycookie implements [request.Limiter] by extracting an HTTP cookie from [http.Request]s.
Package tagbycookie implements [request.Limiter] by extracting an HTTP cookie from [http.Request]s.
Package tagbyheader implements [request.Limiter] by extracting an HTTP header value from [http.Request]s.
Package tagbyheader implements [request.Limiter] by extracting an HTTP header value from [http.Request]s.
Package tagbyip implements [request.Limiter] by extracting Internet Protocol addresses from [http.Request]s.
Package tagbyip implements [request.Limiter] by extracting Internet Protocol addresses from [http.Request]s.

Jump to

Keyboard shortcuts

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