middleware

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 24 Imported by: 18

Documentation

Index

Constants

View Source
const (
	ContextKeySessionID contextKey = "sessionId"

	DefaultSessionIDCookieName = "keel-session"
)
View Source
const (
	ContextKeyTrackingID contextKey = "tracking"

	DefaultTrackingIDCookieName = "keel-tracking"
)

Variables

This section is empty.

Functions

func Compose

func Compose(l *zap.Logger, name string, handler http.Handler, middlewares ...Middleware) http.Handler

func DefaultJWTClaimsProvider added in v0.2.0

func DefaultJWTClaimsProvider() jwt2.Claims

DefaultJWTClaimsProvider function

func DefaultJWTErrorHandler added in v0.2.0

func DefaultJWTErrorHandler(l *zap.Logger, w http.ResponseWriter, r *http.Request, err error) bool

DefaultJWTErrorHandler function

func DefaultJWTInvalidTokenHandler added in v0.2.0

func DefaultJWTInvalidTokenHandler(l *zap.Logger, w http.ResponseWriter, r *http.Request, token *jwt2.Token) bool

DefaultJWTInvalidTokenHandler function

func DefaultJWTMissingTokenHandler added in v0.2.0

func DefaultJWTMissingTokenHandler(l *zap.Logger, w http.ResponseWriter, r *http.Request) (jwt2.Claims, bool)

DefaultJWTMissingTokenHandler function

func DefaultRequestIDGenerator

func DefaultRequestIDGenerator() string

DefaultRequestIDGenerator function

func DefaultSessionIDGenerator added in v0.2.0

func DefaultSessionIDGenerator() string

DefaultSessionIDGenerator function

func DefaultTrackingIDGenerator added in v0.9.1

func DefaultTrackingIDGenerator() string

DefaultTrackingIDGenerator function

func RequiredJWTMissingTokenHandler added in v0.2.0

func RequiredJWTMissingTokenHandler(l *zap.Logger, w http.ResponseWriter, r *http.Request) (jwt2.Claims, bool)

RequiredJWTMissingTokenHandler function

func SessionIDFromContext added in v0.2.0

func SessionIDFromContext(ctx context.Context) string

SessionIDFromContext helper

func TrackingIDFromContext added in v0.9.1

func TrackingIDFromContext(ctx context.Context) string

TrackingIDFromContext helper

func WrapResponseWriter added in v0.2.0

func WrapResponseWriter(w http.ResponseWriter) *responseWriter

Types

type BasicAuthOption added in v0.2.0

type BasicAuthOption func(*BasicAuthOptions)

func BasicAuthWithRealm added in v0.2.0

func BasicAuthWithRealm(v string) BasicAuthOption

BasicAuthWithRealm middleware option

type BasicAuthOptions added in v0.2.0

type BasicAuthOptions struct {
	Realm string
}

func GetDefaultBasicAuthOptions added in v0.2.0

func GetDefaultBasicAuthOptions() BasicAuthOptions

GetDefaultBasicAuthOptions returns the default options

type CORSOption added in v0.2.0

type CORSOption func(*CORSOptions)

func CORSWithAllowCredentials added in v0.2.0

func CORSWithAllowCredentials(v bool) CORSOption

CORSWithAllowCredentials middleware option

func CORSWithAllowHeaders added in v0.2.0

func CORSWithAllowHeaders(v ...string) CORSOption

CORSWithAllowHeaders middleware option

func CORSWithAllowMethods added in v0.2.0

func CORSWithAllowMethods(v ...string) CORSOption

CORSWithAllowMethods middleware option

func CORSWithAllowOrigins added in v0.2.0

func CORSWithAllowOrigins(v ...string) CORSOption

CORSWithAllowOrigins middleware option

func CORSWithExposeHeaders added in v0.2.0

func CORSWithExposeHeaders(v ...string) CORSOption

CORSWithExposeHeaders middleware option

func CORSWithMaxAge added in v0.2.0

func CORSWithMaxAge(v int) CORSOption

CORSWithMaxAge middleware option

type CORSOptions added in v0.2.0

type CORSOptions struct {
	AllowOrigins     []string
	AllowMethods     []string
	AllowHeaders     []string
	AllowCredentials bool
	ExposeHeaders    []string
	MaxAge           int
}

func GetDefaultCORSOptions added in v0.2.0

func GetDefaultCORSOptions() CORSOptions

GetDefaultCORSOptions returns the default options

type CookieTokenProviderOption added in v0.2.0

type CookieTokenProviderOption func(*CookieTokenProviderOptions)

type CookieTokenProviderOptions added in v0.2.0

type CookieTokenProviderOptions struct{}

func GetDefaultCookieTokenOptions added in v0.2.0

func GetDefaultCookieTokenOptions() CookieTokenProviderOptions

GetDefaultCookieTokenOptions returns the default options

type HeaderTokenProviderOption added in v0.2.0

type HeaderTokenProviderOption func(*HeaderTokenProviderOptions)

func HeaderTokenProviderWithHeader added in v0.2.0

func HeaderTokenProviderWithHeader(v string) HeaderTokenProviderOption

HeaderTokenProviderWithHeader middleware option

func HeaderTokenProviderWithPrefix added in v0.2.0

func HeaderTokenProviderWithPrefix(v string) HeaderTokenProviderOption

HeaderTokenProviderWithPrefix middleware option

type HeaderTokenProviderOptions added in v0.2.0

type HeaderTokenProviderOptions struct {
	Prefix string
	Header string
}

func GetDefaultHeaderTokenOptions added in v0.2.0

func GetDefaultHeaderTokenOptions() HeaderTokenProviderOptions

GetDefaultHeaderTokenOptions returns the default options

type JWTClaimsProvider added in v0.2.0

type JWTClaimsProvider func() jwt2.Claims

type JWTErrorHandler added in v0.2.0

type JWTErrorHandler func(*zap.Logger, http.ResponseWriter, *http.Request, error) bool

type JWTInvalidTokenHandler added in v0.2.0

type JWTInvalidTokenHandler func(*zap.Logger, http.ResponseWriter, *http.Request, *jwt2.Token) bool

type JWTMissingTokenHandler added in v0.2.0

type JWTMissingTokenHandler func(*zap.Logger, http.ResponseWriter, *http.Request) (jwt2.Claims, bool)

type JWTOption added in v0.2.0

type JWTOption func(*JWTOptions)

func JWTWithClaimsProvider added in v0.2.0

func JWTWithClaimsProvider(v JWTClaimsProvider) JWTOption

JWTWithClaimsProvider middleware option

func JWTWithErrorHandler added in v0.2.0

func JWTWithErrorHandler(v JWTErrorHandler) JWTOption

JWTWithErrorHandler middleware option

func JWTWithInvalidTokenHandler added in v0.2.0

func JWTWithInvalidTokenHandler(v JWTInvalidTokenHandler) JWTOption

JWTWithInvalidTokenHandler middleware option

func JWTWithMissingTokenHandler added in v0.2.0

func JWTWithMissingTokenHandler(v JWTMissingTokenHandler) JWTOption

JWTWithMissingTokenHandler middleware option

func JWTWithSetContext added in v0.2.1

func JWTWithSetContext(v bool) JWTOption

func JWTWithTokenProvider added in v0.2.0

func JWTWithTokenProvider(v TokenProvider) JWTOption

JWTWithTokenProvider middleware option

type JWTOptions added in v0.2.0

type JWTOptions struct {
	SetContext          bool
	TokenProvider       TokenProvider
	ClaimsProvider      JWTClaimsProvider
	MissingTokenHandler JWTMissingTokenHandler
	InvalidTokenHandler JWTInvalidTokenHandler
	ErrorHandler        JWTErrorHandler
}

func GetDefaultJWTOptions added in v0.2.0

func GetDefaultJWTOptions() JWTOptions

GetDefaultJWTOptions returns the default options

type LoggerOption added in v0.2.0

type LoggerOption func(*LoggerOptions)

func LoggerWithMessage added in v0.2.4

func LoggerWithMessage(v string) LoggerOption

LoggerWithMessage middleware option

type LoggerOptions added in v0.2.0

type LoggerOptions struct {
	Message string
}

func GetDefaultLoggerOptions added in v0.2.0

func GetDefaultLoggerOptions() LoggerOptions

GetDefaultLoggerOptions returns the default options

type Middleware

type Middleware func(*zap.Logger, string, http.Handler) http.Handler

Middleware your way to handle requests

func BasicAuth

func BasicAuth(username string, passwordHash []byte, opts ...BasicAuthOption) Middleware

BasicAuth middleware

func BasicAuthWithOptions added in v0.2.0

func BasicAuthWithOptions(username string, passwordHash []byte, opts BasicAuthOptions) Middleware

BasicAuthWithOptions middleware

func CORS

func CORS(opts ...CORSOption) Middleware

CORS middleware

func CORSWithOptions added in v0.2.0

func CORSWithOptions(opts CORSOptions) Middleware

CORSWithOptions middleware

func JWT added in v0.2.0

func JWT(jwt *jwt.JWT, contextKey interface{}, opts ...JWTOption) Middleware

JWT middleware

func JWTWithOptions added in v0.2.0

func JWTWithOptions(jwt *jwt.JWT, contextKey interface{}, opts JWTOptions) Middleware

JWTWithOptions middleware

func Logger

func Logger(opts ...LoggerOption) Middleware

Logger middleware

func LoggerWithOptions added in v0.2.0

func LoggerWithOptions(opts LoggerOptions) Middleware

LoggerWithOptions middleware

func PoweredByHeader added in v0.2.6

func PoweredByHeader(opts ...PoweredByHeaderOption) Middleware

PoweredByHeader middleware

func PoweredByHeaderWithOptions added in v0.2.6

func PoweredByHeaderWithOptions(opts PoweredByHeaderOptions) Middleware

PoweredByHeaderWithOptions middleware

func Recover

func Recover(opts ...RecoverOption) Middleware

Recover middleware

func RecoverWithOptions added in v0.2.0

func RecoverWithOptions(opts RecoverOptions) Middleware

RecoverWithOptions middleware

func RequestID

func RequestID(opts ...RequestIDOption) Middleware

RequestID middleware

func RequestIDWithOptions added in v0.2.0

func RequestIDWithOptions(opts RequestIDOptions) Middleware

RequestIDWithOptions middleware

func ResponseTime added in v0.2.0

func ResponseTime(opts ...ResponseTimeOption) Middleware

ResponseTime middleware

func ResponseTimeWithOptions added in v0.2.0

func ResponseTimeWithOptions(opts ResponseTimeOptions) Middleware

ResponseTimeWithOptions middleware

func ServerHeader added in v0.2.6

func ServerHeader(opts ...ServerHeaderOption) Middleware

ServerHeader middleware

func ServerHeaderWithOptions added in v0.2.6

func ServerHeaderWithOptions(opts ServerHeaderOptions) Middleware

ServerHeaderWithOptions middleware

func SessionID added in v0.2.0

func SessionID(opts ...SessionIDOption) Middleware

SessionID middleware

func SessionIDWithOptions added in v0.2.0

func SessionIDWithOptions(opts SessionIDOptions) Middleware

SessionIDWithOptions middleware

func Skip added in v0.2.0

func Skip(mw Middleware, skippers ...Skipper) Middleware

func Telemetry

func Telemetry(opts ...TelemetryOption) Middleware

Telemetry middleware

func TelemetryWithOptions added in v0.2.0

func TelemetryWithOptions(opts TelemetryOptions) Middleware

TelemetryWithOptions middleware

func TokenAuth added in v0.2.0

func TokenAuth(token string, opts ...TokenAuthOption) Middleware

TokenAuth middleware

func TokenAuthWithOptions added in v0.2.0

func TokenAuthWithOptions(token string, opts TokenAuthOptions) Middleware

TokenAuthWithOptions middleware

func TrackingID added in v0.9.1

func TrackingID(opts ...TrackingIDOption) Middleware

TrackingID middleware

func TrackingIDWithOptions added in v0.9.1

func TrackingIDWithOptions(opts TrackingIDOptions) Middleware

TrackingIDWithOptions middleware

type PoweredByHeaderOption added in v0.2.6

type PoweredByHeaderOption func(*PoweredByHeaderOptions)

func PoweredByHeaderWithHeader added in v0.2.6

func PoweredByHeaderWithHeader(v string) PoweredByHeaderOption

PoweredByHeaderWithHeader middleware option

func PoweredByHeaderWithMessage added in v0.2.6

func PoweredByHeaderWithMessage(v string) PoweredByHeaderOption

PoweredByHeaderWithMessage middleware option

type PoweredByHeaderOptions added in v0.2.6

type PoweredByHeaderOptions struct {
	Header  string
	Message string
}

func GetDefaultPoweredByHeaderOptions added in v0.2.6

func GetDefaultPoweredByHeaderOptions() PoweredByHeaderOptions

GetDefaultPoweredByHeaderOptions returns the default options

type RecoverOption added in v0.2.0

type RecoverOption func(*RecoverOptions)

func RecoverWithDisablePrintStack added in v0.2.0

func RecoverWithDisablePrintStack(v bool) RecoverOption

RecoverWithDisablePrintStack middleware option

type RecoverOptions added in v0.2.0

type RecoverOptions struct {
	DisablePrintStack bool
}

func GetDefaultRecoverOptions added in v0.2.0

func GetDefaultRecoverOptions() RecoverOptions

GetDefaultRecoverOptions returns the default options

type RequestIDGenerator added in v0.2.0

type RequestIDGenerator func() string

type RequestIDOption added in v0.2.0

type RequestIDOption func(*RequestIDOptions)

func RequestIDWithGenerator added in v0.2.0

func RequestIDWithGenerator(v RequestIDGenerator) RequestIDOption

RequestIDWithGenerator middleware option

func RequestIDWithResponseHeader added in v0.2.0

func RequestIDWithResponseHeader(v string) RequestIDOption

RequestIDWithResponseHeader middleware option

func RequestIDWithSetResponseHeader added in v0.2.0

func RequestIDWithSetResponseHeader(v bool) RequestIDOption

RequestIDWithSetResponseHeader middleware option

type RequestIDOptions added in v0.2.0

type RequestIDOptions struct {
	Generator         RequestIDGenerator
	ResponseHeader    string
	SetResponseHeader bool
}

func GetDefaultRequestIDOptions added in v0.2.0

func GetDefaultRequestIDOptions() RequestIDOptions

GetDefaultRequestIDOptions returns the default options

type ResponseTimeOption added in v0.2.0

type ResponseTimeOption func(*ResponseTimeOptions)

func ResponseTimeWithMaxDuration added in v0.2.0

func ResponseTimeWithMaxDuration(v time.Duration) ResponseTimeOption

ResponseTimeWithMaxDuration middleware option

func ResponseTimeWithMaxDurationMessage added in v0.2.0

func ResponseTimeWithMaxDurationMessage(v string) ResponseTimeOption

ResponseTimeWithMaxDurationMessage middleware option

func ResponseTimeWithSetHeader added in v0.2.0

func ResponseTimeWithSetHeader(v bool) ResponseTimeOption

ResponseTimeWithSetHeader middleware option

type ResponseTimeOptions added in v0.2.0

type ResponseTimeOptions struct {
	SetHeader          bool
	MaxDuration        time.Duration
	MaxDurationMessage string
}

func GetDefaultResponseTimeOptions added in v0.2.0

func GetDefaultResponseTimeOptions() ResponseTimeOptions

GetDefaultResponseTimeOptions returns the default options

type ServerHeaderOption added in v0.2.6

type ServerHeaderOption func(*ServerHeaderOptions)

func ServerHeaderWithHeader added in v0.2.6

func ServerHeaderWithHeader(v string) ServerHeaderOption

ServerHeaderWithHeader middleware option

func ServerHeaderWithName added in v0.2.6

func ServerHeaderWithName(v string) ServerHeaderOption

ServerHeaderWithName middleware option

type ServerHeaderOptions added in v0.2.6

type ServerHeaderOptions struct {
	Header string
	Name   string
}

func GetDefaultServerHeaderOptions added in v0.2.6

func GetDefaultServerHeaderOptions() ServerHeaderOptions

GetDefaultServerHeaderOptions returns the default options

type SessionIDGenerator added in v0.2.0

type SessionIDGenerator func() string

type SessionIDOption added in v0.2.0

type SessionIDOption func(*SessionIDOptions)

func SessionIDWithCookie added in v0.2.0

func SessionIDWithCookie(v cookie.Cookie) SessionIDOption

SessionIDWithCookie middleware option

func SessionIDWithGenerator added in v0.2.0

func SessionIDWithGenerator(v SessionIDGenerator) SessionIDOption

SessionIDWithGenerator middleware option

func SessionIDWithHeader added in v0.2.0

func SessionIDWithHeader(v string) SessionIDOption

func SessionIDWithSetContext added in v0.2.0

func SessionIDWithSetContext(v bool) SessionIDOption

SessionIDWithSetContext middleware option

func SessionIDWithSetCookie added in v0.2.0

func SessionIDWithSetCookie(v bool) SessionIDOption

SessionIDWithSetCookie middleware option

func SessionIDWithSetHeader added in v0.2.0

func SessionIDWithSetHeader(v bool) SessionIDOption

SessionIDWithSetHeader middleware option

type SessionIDOptions added in v0.2.0

type SessionIDOptions struct {
	// Header to look up the session id
	Header string
	// Cookie how to set the cookie
	Cookie cookie.Cookie
	// Generator for the session ids
	Generator SessionIDGenerator
	// SetCookie if true it will create a cookie if not exists
	SetCookie bool
	// SetHeader if true it will set add a request header
	SetHeader bool
	// SetContext if true it will set the context key
	SetContext bool
}

func GetDefaultSessionIDOptions added in v0.2.0

func GetDefaultSessionIDOptions() SessionIDOptions

GetDefaultSessionIDOptions returns the default options

type Skipper added in v0.2.0

type Skipper func(*http.Request) bool

func RequestURIBlacklistSkipper added in v0.2.0

func RequestURIBlacklistSkipper(uris ...string) Skipper

RequestURIBlacklistSkipper returns a HTTPMiddlewareConfig.Skipper which skips the given uris

func RequestURIWhitelistSkipper added in v0.2.0

func RequestURIWhitelistSkipper(uris ...string) Skipper

RequestURIWhitelistSkipper returns a HTTPMiddlewareConfig.Skipper which skips all but the given uris

type TelemetryOption added in v0.2.0

type TelemetryOption func(*TelemetryOptions)

func TelemetryWithName added in v0.2.6

func TelemetryWithName(v string) TelemetryOption

func TelemetryWithOtelOpts added in v0.2.6

func TelemetryWithOtelOpts(v ...otelhttp.Option) TelemetryOption

TelemetryWithOtelOpts middleware options

type TelemetryOptions added in v0.2.0

type TelemetryOptions struct {
	Name     string
	OtelOpts []otelhttp.Option
}

func GetDefaultTelemetryOptions added in v0.2.0

func GetDefaultTelemetryOptions() TelemetryOptions

GetDefaultTelemetryOptions returns the default options

type TokenAuthOption added in v0.2.0

type TokenAuthOption func(*TokenAuthOptions)

func TokenAuthWithTokenProvider added in v0.2.0

func TokenAuthWithTokenProvider(v TokenProvider) TokenAuthOption

TokenAuthWithTokenProvider middleware option

type TokenAuthOptions added in v0.2.0

type TokenAuthOptions struct {
	// TokenProvider function to retrieve the token
	TokenProvider TokenProvider
}

func GetDefaultTokenAuthOptions added in v0.2.0

func GetDefaultTokenAuthOptions() TokenAuthOptions

GetDefaultTokenAuthOptions returns the default options

type TokenProvider added in v0.2.0

type TokenProvider func(r *http.Request) (string, error)

func CookieTokenProvider added in v0.2.0

func CookieTokenProvider(cookieName string, opts ...CookieTokenProviderOption) TokenProvider

func HeaderTokenProvider added in v0.2.0

func HeaderTokenProvider(opts ...HeaderTokenProviderOption) TokenProvider

type TrackingIDGenerator added in v0.9.1

type TrackingIDGenerator func() string

type TrackingIDOption added in v0.9.1

type TrackingIDOption func(*TrackingIDOptions)

func TrackingIDWithCookie added in v0.9.1

func TrackingIDWithCookie(v cookie.Cookie) TrackingIDOption

TrackingIDWithCookie middleware option

func TrackingIDWithGenerator added in v0.9.1

func TrackingIDWithGenerator(v TrackingIDGenerator) TrackingIDOption

TrackingIDWithGenerator middleware option

func TrackingIDWithHeader added in v0.9.1

func TrackingIDWithHeader(v string) TrackingIDOption

func TrackingIDWithSetContext added in v0.9.1

func TrackingIDWithSetContext(v bool) TrackingIDOption

TrackingIDWithSetContext middleware option

func TrackingIDWithSetCookie added in v0.9.1

func TrackingIDWithSetCookie(v bool) TrackingIDOption

TrackingIDWithSetCookie middleware option

func TrackingIDWithSetHeader added in v0.9.1

func TrackingIDWithSetHeader(v bool) TrackingIDOption

TrackingIDWithSetHeader middleware option

type TrackingIDOptions added in v0.9.1

type TrackingIDOptions struct {
	// Header to look up the tracking id
	Header string
	// Cookie how to set the cookie
	Cookie cookie.Cookie
	// Generator for the tracking ids
	Generator TrackingIDGenerator
	// SetCookie if true it will create a cookie if not exists
	SetCookie bool
	// SetHeader if true it will set add a request header
	SetHeader bool
	// SetContext if true it will set the context key
	SetContext bool
}

func GetDefaultTrackingIDOptions added in v0.9.1

func GetDefaultTrackingIDOptions() TrackingIDOptions

GetDefaultTrackingIDOptions returns the default options

Jump to

Keyboard shortcuts

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