Documentation
¶
Index ¶
- Variables
- func AddKeyID(ctx context.Context, id string) context.Context
- func BearerToken(next http.Handler) http.Handler
- func GetKeyID(ctx context.Context) (string, error)
- func HTTPSignedOnly(ks httpsignature.Keystore) func(http.Handler) http.Handler
- func HostTransfer(next http.Handler) http.Handler
- func IPRateLimiterWithStore(ctx context.Context, perMin int, burst int, store throttled.GCRAStoreCtx) func(next http.Handler) http.Handler
- func InstrumentHandler(name string, h http.Handler) http.Handler
- func InstrumentHandlerFunc(name string, f handlers.AppHandler) http.HandlerFunc
- func InstrumentRoundTripper(roundTripper http.RoundTripper, service string) http.RoundTripper
- func Metrics() http.HandlerFunc
- func NewServiceCtx(service interface{}) func(http.Handler) http.Handler
- func NewUpgradeRequiredByMiddleware(cutoff time.Time) func(http.Handler) http.Handler
- func RateLimiter(ctx context.Context, perMin int) func(next http.Handler) http.Handler
- func RateLimiterRedisStore(ctx context.Context, perMin int, burst int, redis *redis.Client, ...) func(next http.Handler) http.Handler
- func RequestIDTransfer(next http.Handler) http.Handler
- func RequestLogger(logger *zerolog.Logger) func(next http.Handler) http.Handler
- func SimpleTokenAuthorizedOnly(next http.Handler) http.Handler
- func VerifyHTTPSignedOnly(verifier httpsignature.ParameterizedKeystoreVerifier) func(http.Handler) http.Handler
- type InstrumentHandlerDef
Constants ¶
This section is empty.
Variables ¶
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", }, ) )
var ( // TokenList is the list of tokens that are accepted as valid TokenList = strings.Split(os.Getenv("TOKEN_LIST"), ",") )
Functions ¶
func BearerToken ¶
BearerToken is a middleware that adds the bearer token included in a request's headers to context
func HTTPSignedOnly ¶
HTTPSignedOnly is a middleware that requires an HTTP request to be signed
func HostTransfer ¶
HostTransfer transfers the request id from header to context
func IPRateLimiterWithStore ¶
func IPRateLimiterWithStore( ctx context.Context, perMin int, burst int, store throttled.GCRAStoreCtx, ) 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 ¶
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 ¶
NewServiceCtx passes a service into the context
func NewUpgradeRequiredByMiddleware ¶
NewUpgradeRequiredByMiddleware passes a service into the context
func RateLimiter ¶
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.Client, keyPrefix string, ) 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 ¶
RequestIDTransfer transfers the request id from header to context
func RequestLogger ¶
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 ¶
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