Documentation
¶
Index ¶
- Variables
- func GetBasicAuthUsername(ctx context.Context) string
- func GetJSONData(ctx context.Context) []byte
- func GetJWTClaims(ctx context.Context) jwt.Claims
- func GetRequestID(ctx context.Context) string
- func NewAuthMiddleware(authorizer Authorizer, configs ...AuthMiddlewareConfigFunc) chevron.Middleware
- func NewGzip(configs ...GzipMiddlewareConfigFunc) chevron.Middleware
- func NewJWTHeaderExtractor(name, scheme string) request.Extractor
- func NewJWTQueryExtractor(name string) request.Extractor
- func NewLogging(configs ...LoggingConfigFunc) chevron.Middleware
- func NewRecovery(configs ...RecoverConfigFunc) chevron.Middleware
- func NewResponseCache(cache gache.Cache, configs ...CacheMiddlewareConfigFunc) chevron.Middleware
- func NewSchemaMiddleware(path string, configs ...SchemaConfigFunc) chevron.Middleware
- type AuthMiddleware
- type AuthMiddlewareConfigFunc
- type AuthResult
- type Authorizer
- type AuthorizerFunc
- type BasicAuthValidator
- type CacheMiddleware
- type CacheMiddlewareConfigFunc
- type ErrorFactory
- type GzipMiddleware
- type GzipMiddlewareConfigFunc
- type JWTAuthorizerConfigFunc
- type JWTClaimsFactory
- type LoggingConfigFunc
- type LoggingMiddleware
- type PanicErrorFactory
- type RecoverConfigFunc
- type RecoverMiddleware
- type RequestIDConfigFunc
- type RequestIDGenerator
- type RequestIDMiddleware
- type ResponseFactory
- type SchemaBadRequestFactory
- type SchemaConfigFunc
- type SchemaMiddleware
- type SchemaUnprocessableEntityFactory
Constants ¶
This section is empty.
Variables ¶
var TokenAuthPayload = tokenAuthPayload("chevron.middleware.auth")
var TokenJSONData = tokenJSONData("chevron.middleware.json_data")
var TokenRequestID = tokenRequestID("chevron.middleware.request_id")
TokenRequestID is the unique token to which the current request's unique ID is written to the request context.
Functions ¶
func GetBasicAuthUsername ¶
func GetJSONData ¶
func GetJWTClaims ¶
func GetRequestID ¶
GetRequestID retrieves the current request's unique ID. If no request ID is registered with this context, the empty string is returned.
func NewAuthMiddleware ¶
func NewAuthMiddleware(authorizer Authorizer, configs ...AuthMiddlewareConfigFunc) chevron.Middleware
func NewGzip ¶
func NewGzip(configs ...GzipMiddlewareConfigFunc) chevron.Middleware
func NewJWTHeaderExtractor ¶
func NewJWTQueryExtractor ¶
func NewLogging ¶
func NewLogging(configs ...LoggingConfigFunc) chevron.Middleware
func NewRecovery ¶
func NewRecovery(configs ...RecoverConfigFunc) chevron.Middleware
NewRecovery creates middleware that captures panics from the handler and converts them to 500-level responses. The value of the panic is logged at error level.
func NewResponseCache ¶
func NewResponseCache( cache gache.Cache, configs ...CacheMiddlewareConfigFunc, ) chevron.Middleware
NewResponseCache creates middleware that stores the complete response in a cache instance. The wrapped handler is not invoked if a response payload for the given request is available in the cache.
func NewSchemaMiddleware ¶
func NewSchemaMiddleware(path string, configs ...SchemaConfigFunc) chevron.Middleware
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct {
// contains filtered or unexported fields
}
type AuthMiddlewareConfigFunc ¶
type AuthMiddlewareConfigFunc func(*AuthMiddleware)
func WithAuthErrorFactory ¶
func WithAuthErrorFactory(factory ErrorFactory) AuthMiddlewareConfigFunc
func WithAuthForbiddenResponseFactory ¶
func WithAuthForbiddenResponseFactory(factory ResponseFactory) AuthMiddlewareConfigFunc
func WithAuthUnauthorizedResponseFactory ¶
func WithAuthUnauthorizedResponseFactory(factory ErrorFactory) AuthMiddlewareConfigFunc
type AuthResult ¶
type AuthResult int
const ( AuthResultInvalid AuthResult = iota AuthResultOK AuthResultForbidden )
type Authorizer ¶
type Authorizer interface {
Authorize(context.Context, *http.Request) (AuthResult, interface{}, error)
}
func NewBasicAuthorizer ¶
func NewBasicAuthorizer(validator BasicAuthValidator) Authorizer
func NewJWTAuthorizer ¶
func NewJWTAuthorizer(keyfunc jwt.Keyfunc, configs ...JWTAuthorizerConfigFunc) Authorizer
type AuthorizerFunc ¶
func (AuthorizerFunc) Authorize ¶
func (f AuthorizerFunc) Authorize(ctx context.Context, req *http.Request) (AuthResult, interface{}, error)
type BasicAuthValidator ¶
type CacheMiddleware ¶
type CacheMiddleware struct {
// contains filtered or unexported fields
}
type CacheMiddlewareConfigFunc ¶
type CacheMiddlewareConfigFunc func(*CacheMiddleware)
CacheMiddlewareConfigFunc is a function used to initialize a new cache middleware instance.
func WithCacheErrorFactory ¶
func WithCacheErrorFactory(factory ErrorFactory) CacheMiddlewareConfigFunc
func WithCacheTags ¶
func WithCacheTags(tags ...string) CacheMiddlewareConfigFunc
WithCacheTags sets the tags applied to keys written to the cache by the associated middleware.
type ErrorFactory ¶
func NewBasicUnauthorizedResponseFactory ¶
func NewBasicUnauthorizedResponseFactory(realm string) ErrorFactory
type GzipMiddleware ¶
type GzipMiddleware struct {
// contains filtered or unexported fields
}
type GzipMiddlewareConfigFunc ¶
type GzipMiddlewareConfigFunc func(*GzipMiddleware)
func WithGzipLevel ¶
func WithGzipLevel(level int) GzipMiddlewareConfigFunc
type JWTAuthorizerConfigFunc ¶
type JWTAuthorizerConfigFunc func(*jwtAuthorizer)
func WithJWTAuthClaimsFactory ¶
func WithJWTAuthClaimsFactory(factory JWTClaimsFactory) JWTAuthorizerConfigFunc
func WithJWTAuthExtractor ¶
func WithJWTAuthExtractor(extractor request.Extractor) JWTAuthorizerConfigFunc
type JWTClaimsFactory ¶
type JWTClaimsFactory func() jwt.Claims
type LoggingConfigFunc ¶
type LoggingConfigFunc func(m *LoggingMiddleware)
func WithLoggingClock ¶
func WithLoggingClock(clock glock.Clock) LoggingConfigFunc
type LoggingMiddleware ¶
type LoggingMiddleware struct {
// contains filtered or unexported fields
}
type PanicErrorFactory ¶
type RecoverConfigFunc ¶
type RecoverConfigFunc func(m *RecoverMiddleware)
func WithRecoverErrorFactory ¶
func WithRecoverErrorFactory(factory PanicErrorFactory) RecoverConfigFunc
func WithRecoverLogAllGoroutines ¶
func WithRecoverLogAllGoroutines(logAllGoroutines bool) RecoverConfigFunc
func WithRecoverStackBufferSize ¶
func WithRecoverStackBufferSize(stackBufferSize int) RecoverConfigFunc
type RecoverMiddleware ¶
type RecoverMiddleware struct {
// contains filtered or unexported fields
}
type RequestIDConfigFunc ¶
type RequestIDConfigFunc func(m *RequestIDMiddleware)
func WithRequestIDErrorFactory ¶
func WithRequestIDErrorFactory(factory ErrorFactory) RequestIDConfigFunc
func WithRequestIDGenerator ¶
func WithRequestIDGenerator(generator RequestIDGenerator) RequestIDConfigFunc
type RequestIDGenerator ¶
type RequestIDMiddleware ¶
type RequestIDMiddleware struct {
// contains filtered or unexported fields
}
func NewRequestID ¶
func NewRequestID(configs ...RequestIDConfigFunc) *RequestIDMiddleware
NewRequestID creates middleware that generates a unique ID for the request. If the header X-Request-ID is present in the request, that value is used instead. The request ID is added to the context and to logger attributes, and the X-Request-ID header is added to the wrapped handler's resulting response.
type ResponseFactory ¶
type SchemaBadRequestFactory ¶
type SchemaConfigFunc ¶
type SchemaConfigFunc func(m *SchemaMiddleware)
func WithSchemaBadRequestFactory ¶
func WithSchemaBadRequestFactory(factory SchemaBadRequestFactory) SchemaConfigFunc
func WithSchemaErrorFactory ¶
func WithSchemaErrorFactory(factory ErrorFactory) SchemaConfigFunc
func WithSchemaUnprocessableEntityFactory ¶
func WithSchemaUnprocessableEntityFactory(factory SchemaUnprocessableEntityFactory) SchemaConfigFunc
type SchemaMiddleware ¶
type SchemaMiddleware struct {
// contains filtered or unexported fields
}
type SchemaUnprocessableEntityFactory ¶
type SchemaUnprocessableEntityFactory func([]gojsonschema.ResultError) response.Response