middleware

package
v0.0.0-...-f003305 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.0 Imports: 30 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ConcurrentGoRoutines holds the number of go outines
	ConcurrentGoRoutines = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "concurrent_goroutine",
			Help: "Gauge that holds the current number of goroutines",
		},
		[]string{
			"method",
		},
	)
)
View Source
var (
	// TokenList is the list of tokens that are accepted as valid
	TokenList = strings.Split(os.Getenv("TOKEN_LIST"), ",")
)

Functions

func AddKeyID

func AddKeyID(ctx context.Context, id string) context.Context

AddKeyID - Helpful for test cases

func BearerToken

func BearerToken(next http.Handler) http.Handler

BearerToken is a middleware that adds the bearer token included in a request's headers to context

func GetKeyID

func GetKeyID(ctx context.Context) (string, error)

GetKeyID retrieves the http signing keyID from the context

func HTTPSignedOnly

func HTTPSignedOnly(ks httpsignature.Keystore) func(http.Handler) http.Handler

HTTPSignedOnly is a middleware that requires an HTTP request to be signed

func HostTransfer

func HostTransfer(next http.Handler) http.Handler

HostTransfer transfers the request id from header to context

func IPRateLimiterWithStore

func IPRateLimiterWithStore(
	ctx context.Context,
	perMin int,
	burst int,
	store throttled.GCRAStore,
) func(next http.Handler) http.Handler

IPRateLimiterWithStore rate limits based on IP using a provided store and a GCRA leaky bucket algorithm. This can be a simple memory store, a Redis store, or other stores for multi-instance synchronization. See https://github.com/throttled/throttled/tree/master/store for details.

func InstrumentHandler

func InstrumentHandler(name string, h http.Handler) http.Handler

InstrumentHandler instruments an http.Handler to capture metrics like the number the total number of requests served and latency information

func InstrumentHandlerFunc

func InstrumentHandlerFunc(name string, f handlers.AppHandler) http.HandlerFunc

InstrumentHandlerFunc - helper to wrap up a handler func

func InstrumentRoundTripper

func InstrumentRoundTripper(roundTripper http.RoundTripper, service string) http.RoundTripper

InstrumentRoundTripper instruments an http.RoundTripper to capture metrics like the number of active requests, the total number of requests made and latency information

func Metrics

func Metrics() http.HandlerFunc

Metrics returns a http.HandlerFunc for the prometheus /metrics endpoint

func NewServiceCtx

func NewServiceCtx(service interface{}) func(http.Handler) http.Handler

NewServiceCtx passes a service into the context

func NewUpgradeRequiredByMiddleware

func NewUpgradeRequiredByMiddleware(cutoff time.Time) func(http.Handler) http.Handler

NewUpgradeRequiredByMiddleware passes a service into the context

func RateLimiter

func RateLimiter(ctx context.Context, perMin int) func(next http.Handler) http.Handler

RateLimiter rate limits the number of requests a user from a single IP address can make using a simple in-memory store that will not synchronize across instances.

func RateLimiterRedisStore

func RateLimiterRedisStore(
	ctx context.Context,
	perMin int,
	burst int,
	redis *redis.Pool,
	keyPrefix string,
	db int,
) func(next http.Handler) http.Handler

RateLimiterRedisStore rate limits the number of requests a user from a single IP address can make and coordinates request counts between instances using Redis.

func RequestIDTransfer

func RequestIDTransfer(next http.Handler) http.Handler

RequestIDTransfer transfers the request id from header to context

func RequestLogger

func RequestLogger(logger *zerolog.Logger) func(next http.Handler) http.Handler

RequestLogger logs at the start and stop of incoming HTTP requests as well as recovers from panics Modified version of RequestLogger from github.com/rs/zerolog Added support for sending captured panic to Sentry

func SimpleTokenAuthorizedOnly

func SimpleTokenAuthorizedOnly(next http.Handler) http.Handler

SimpleTokenAuthorizedOnly is a middleware that restricts access to requests with a valid bearer token via context NOTE the valid token is populated via BearerToken

func VerifyHTTPSignedOnly

func VerifyHTTPSignedOnly(verifier httpsignature.ParameterizedKeystoreVerifier) func(http.Handler) http.Handler

VerifyHTTPSignedOnly is a middleware that requires an HTTP request to be signed which takes a parameterized http signature verifier

Types

type InstrumentHandlerDef

type InstrumentHandlerDef func(name string, h http.Handler) http.Handler

InstrumentHandlerDef - definition of an instrument handler http.Handler

Jump to

Keyboard shortcuts

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