middleware

package
v0.0.0-...-d33e5ae Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TokenAuthPayload = tokenAuthPayload("chevron.middleware.auth")
View Source
var TokenJSONData = tokenJSONData("chevron.middleware.json_data")
View Source
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 GetBasicAuthUsername(ctx context.Context) string

func GetJSONData

func GetJSONData(ctx context.Context) []byte

func GetJWTClaims

func GetJWTClaims(ctx context.Context) jwt.Claims

func GetRequestID

func GetRequestID(ctx context.Context) string

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 NewJWTHeaderExtractor(name, scheme string) request.Extractor

func NewJWTQueryExtractor

func NewJWTQueryExtractor(name string) request.Extractor

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
}

func (*AuthMiddleware) Convert

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
	AuthResultUnauthorized
)

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

type AuthorizerFunc func(context.Context, *http.Request) (AuthResult, interface{}, error)

func (AuthorizerFunc) Authorize

func (f AuthorizerFunc) Authorize(ctx context.Context, req *http.Request) (AuthResult, interface{}, error)

type BasicAuthValidator

type BasicAuthValidator func(context.Context, string, string) (bool, error)

type CacheMiddleware

type CacheMiddleware struct {
	// contains filtered or unexported fields
}

func (*CacheMiddleware) Convert

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

type ErrorFactory func(error) response.Response

func NewBasicUnauthorizedResponseFactory

func NewBasicUnauthorizedResponseFactory(realm string) ErrorFactory

type GzipMiddleware

type GzipMiddleware struct {
	// contains filtered or unexported fields
}

func (*GzipMiddleware) Convert

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
}

func (*LoggingMiddleware) Convert

type PanicErrorFactory

type PanicErrorFactory func(interface{}) response.Response

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
}

func (*RecoverMiddleware) Convert

type RequestIDConfigFunc

type RequestIDConfigFunc func(m *RequestIDMiddleware)

func WithRequestIDErrorFactory

func WithRequestIDErrorFactory(factory ErrorFactory) RequestIDConfigFunc

func WithRequestIDGenerator

func WithRequestIDGenerator(generator RequestIDGenerator) RequestIDConfigFunc

type RequestIDGenerator

type RequestIDGenerator func() (string, error)

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.

func (*RequestIDMiddleware) Convert

type ResponseFactory

type ResponseFactory func() response.Response

type SchemaBadRequestFactory

type SchemaBadRequestFactory func() response.Response

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
}

func (*SchemaMiddleware) Convert

type SchemaUnprocessableEntityFactory

type SchemaUnprocessableEntityFactory func([]gojsonschema.ResultError) response.Response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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