middleware

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: MPL-2.0 Imports: 29 Imported by: 0

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 added in v0.5.0

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 added in v0.1.2

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

GetKeyID retrieves the http signing keyID from the context

func HTTPSignedOnly added in v0.1.2

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

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

func HostTransfer added in v0.5.0

func HostTransfer(next http.Handler) http.Handler

HostTransfer transfers the request id from header to context

func IPRateLimiterWithStore added in v0.5.0

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 added in v0.1.1

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 added in v0.3.0

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

NewServiceCtx passes a service into the context

func RateLimiter added in v0.2.0

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 added in v0.5.0

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 added in v0.3.0

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 added in v0.5.0

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

This section is empty.

Jump to

Keyboard shortcuts

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