Documentation ¶
Overview ¶
Package middleware provides a collection of middleware functions that handles various aspects of request handling, such as authentication, logging, tracing, and metrics collection.
Index ¶
- func APIKeyAuthMiddleware(validator func(apiKey string) bool, apiKeys ...string) func(handler http.Handler) http.Handler
- func BasicAuthMiddleware(basicAuthProvider BasicAuthProvider) func(handler http.Handler) http.Handler
- func CORS() func(inner http.Handler) http.Handler
- func Logging(logger logger) func(inner http.Handler) http.Handler
- func Metrics(metrics metrics) func(inner http.Handler) http.Handler
- func OAuth(key PublicKeyProvider) func(inner http.Handler) http.Handler
- func Tracer(inner http.Handler) http.Handler
- type BasicAuthProvider
- type JSONWebKey
- type JWKNotFound
- type JWKS
- type JWKSProvider
- type JWTClaim
- type OauthConfigs
- type PublicKeyProvider
- type PublicKeys
- type RequestLog
- type StatusResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIKeyAuthMiddleware ¶ added in v1.1.1
func APIKeyAuthMiddleware(validator func(apiKey string) bool, apiKeys ...string) func(handler http.Handler) http.Handler
APIKeyAuthMiddleware creates a middleware function that enforces API key authentication based on the provided API keys or a validation function.
func BasicAuthMiddleware ¶ added in v1.1.1
func BasicAuthMiddleware(basicAuthProvider BasicAuthProvider) func(handler http.Handler) http.Handler
BasicAuthMiddleware creates a middleware function that enforces basic authentication using the provided BasicAuthProvider.
func CORS ¶
CORS ia a middleware that adds CORS (Cross-Origin Resource Sharing) headers to the response.
func Logging ¶
Logging is a middleware which logs response status and time in milliseconds along with other data.
func Metrics ¶ added in v0.3.0
Metrics is a middleware that records request response time metrics using the provided metrics interface.
Types ¶
type BasicAuthProvider ¶ added in v1.1.1
type BasicAuthProvider struct { Users map[string]string ValidateFunc func(username, password string) bool }
BasicAuthProvider represents a basic authentication provider.
type JSONWebKey ¶ added in v1.1.1
type JSONWebKey struct { ID string `json:"kid"` Type string `json:"kty"` Modulus string `json:"n"` PublicExponent string `json:"e"` PrivateExponent string `json:"d"` }
JSONWebKey represents a JSON Web Key.
type JWKNotFound ¶ added in v1.1.1
type JWKNotFound struct { }
JWKNotFound is an error type indicating a missing JSON Web Key Set (JWKS).
func (JWKNotFound) Error ¶ added in v1.1.1
func (i JWKNotFound) Error() string
type JWKS ¶ added in v1.1.1
type JWKS struct {
Keys []JSONWebKey `json:"keys"`
}
JWKS represents a JSON Web Key Set.
type JWKSProvider ¶ added in v1.1.1
type JWTClaim ¶ added in v1.1.1
type JWTClaim string
JWTClaim represents a custom key used to store JWT claims within the request context.
type OauthConfigs ¶ added in v1.1.1
type OauthConfigs struct { Provider JWKSProvider RefreshInterval time.Duration }
OauthConfigs holds configuration for OAuth middleware.
type PublicKeyProvider ¶ added in v1.1.1
PublicKeyProvider defines an interface for retrieving a public key by its key ID.
func NewOAuth ¶ added in v1.1.1
func NewOAuth(config OauthConfigs) PublicKeyProvider
NewOAuth creates a PublicKeyProvider that periodically fetches and updates public keys from a JWKS endpoint.
type PublicKeys ¶ added in v1.1.1
type PublicKeys struct {
// contains filtered or unexported fields
}
PublicKeys stores a map of public keys identified by their key ID (kid).
type RequestLog ¶
type RequestLog struct { TraceID string `json:"trace_id,omitempty"` SpanID string `json:"span_id,omitempty"` StartTime string `json:"start_time,omitempty"` ResponseTime int64 `json:"response_time,omitempty"` Method string `json:"method,omitempty"` UserAgent string `json:"user_agent,omitempty"` IP string `json:"ip,omitempty"` URI string `json:"uri,omitempty"` Response int `json:"response,omitempty"` }
RequestLog represents a log entry for HTTP requests.
func (*RequestLog) PrettyPrint ¶ added in v1.4.0
func (rl *RequestLog) PrettyPrint(writer io.Writer)
type StatusResponseWriter ¶
type StatusResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
StatusResponseWriter Defines own Response Writer to be used for logging of status - as http.ResponseWriter does not let us read status.
func (*StatusResponseWriter) WriteHeader ¶
func (w *StatusResponseWriter) WriteHeader(status int)