Documentation ¶
Index ¶
- func RegisterMetrics()
- type CORSOpts
- type Chain
- type Handler
- func WithAuthSigningMethodHS256(secret string, audience string, issuer string) Handler
- func WithAuthSigningMethodRS256(jwksEndpoint string, audience string, issuer string) Handler
- func WithCORS(opts CORSOpts) Handler
- func WithCacheControl() Handler
- func WithInstrument() Handler
- func WithLogging() Handler
- func WithPanicRecovery() Handler
- func WithRequiredHeaderValues(requiredHeaderValues map[string]string) Handler
- func WithRequiredHeaders(requiredHeaders []string) Handler
- func WithTimeoutForNonLongRunningRequests(requestTimeout time.Duration) Handler
- type JSONWebKeys
- type Jwks
- type StacktracePred
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterMetrics ¶ added in v1.1.0
func RegisterMetrics()
RegisterMetrics registers metrics of all Nelly supported middlewares
Types ¶
type CORSOpts ¶ added in v1.1.1
type CORSOpts struct { AllowedOriginPatterns []string AllowedMethods []string AllowedHeaders []string ExposedHeaders []string AllowCredentials bool }
CORSOpts is the configuration that will be used by WithCORS
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain is a list of a middleware handlers. Chain is effectively immutable: once created, it will always hold the same set of handlers in the same order.
func Classic ¶
func Classic() Chain
Classic returns a new Chain with some default middleware handlers already in the chain with the following order:
WithPanicRecovery (Panic Recovery Handler), WithLogging (Logging Handler), WithInstrument (Prometheus Metrics Handler), WithCacheControl (Cache-Control header handler)
func (Chain) Append ¶
Append extends a chain, adding the specified handlers as the last ones in the request flow.
Append returns a new chain, leaving the original one untouched.
func (Chain) Extend ¶
Extend extends a chain by adding the specified chain as the last one in the request flow.
Extend returns a new chain, leaving the original one untouched.
func (Chain) Then ¶
func (s Chain) Then(h httprouter.Handle) httprouter.Handle
Then chains the handlers and returns the final httprouter.Handle.
NewChain(m1, m2, m3).Then(h)
is equivalent to:
m1(m2(m3(h)))
When the request comes in, it will be passed to m1, then m2, then m3 and finally, the given handler (assuming every handlers calls the following one).
type Handler ¶
type Handler func(httprouter.Handle) httprouter.Handle
A Handler (middleware handler) is a generic function that takes httprouter.Handle and retrun httprouter.Handle. It is differnet from the common signature of middleware handler that use http.Handler because it uses julienschmidt/httprouter instead.
func WithAuthSigningMethodHS256 ¶
WithAuthSigningMethodHS256 handler authinticates requests with JWT token using HS256 algorithm
func WithAuthSigningMethodRS256 ¶
WithAuthSigningMethodRS256 handler authinticates requests with JWT token using RS256 algorithm
func WithCORS ¶
WithCORS handler is a simple CORS implementation that wraps an httprouter.Handle. Pass nil for allowedMethods and allowedHeaders to use the defaults. If allowedOriginPatterns is empty, no CORS support is installed.
func WithCacheControl ¶
func WithCacheControl() Handler
WithCacheControl handler sets the Cache-Control header to "no-cache, private" because all servers are supposed to be protected by authn/authz. see https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#defining_optimal_cache-control_policy
func WithInstrument ¶
func WithInstrument() Handler
WithInstrument handler wraps httprouter.Handle to record prometheus metrics Recorded metrics:
func WithLogging ¶
func WithLogging() Handler
WithLogging handler wraps httprouter.Handle with logging
func WithPanicRecovery ¶
func WithPanicRecovery() Handler
WithPanicRecovery handler wraps an httprouter.Handle to recover and log panics
func WithRequiredHeaderValues ¶
WithRequiredHeaderValues handler checks if a map of headers are set on requests. If any header from the map doesn't exist or don't equal the values in requiredHeaderValues, the handler will return StatusBadRequest
func WithRequiredHeaders ¶
WithRequiredHeaders handler checks if a list of headers are set on requests. If any header from the list doesn't exist, the handler will return StatusBadRequest
func WithTimeoutForNonLongRunningRequests ¶ added in v1.1.1
WithTimeoutForNonLongRunningRequests handler times out non-long-running requests after the duration given by requestTimeout.
type JSONWebKeys ¶
type JSONWebKeys struct { Kty string `json:"kty"` Kid string `json:"kid"` Use string `json:"use"` N string `json:"n"` E string `json:"e"` X5c []string `json:"x5c"` }
JSONWebKeys is a JSON Web Key
type Jwks ¶
type Jwks struct {
Keys []JSONWebKeys `json:"keys"`
}
Jwks is a set of keys which contains the public keys used to verify JWT issued by the authorization server and signed using the RS256 signing algorithm.
type StacktracePred ¶
StacktracePred returns true if a stacktrace should be logged for this status.
func StatusIsNot ¶
func StatusIsNot(statuses ...int) StacktracePred
StatusIsNot returns a StacktracePred which will cause stacktraces to be logged for any status *not* in the given list.