Documentation
¶
Overview ¶
Package middleware provides HTTP middleware functionality. Includes rate limiting, compression, request body limiting, metrics collection and other middleware.
Package middleware provides HTTP middleware functionality. Includes internationalization language detection middleware.
Package middleware provides HTTP middleware functionality. Includes rate limiting, compression, request body limiting, metrics collection and other middleware.
Package middleware provides HTTP middleware functionality. Includes rate limiting, compression, request body limiting, metrics collection and other middleware.
Index ¶
- func ErrorHandlerMiddleware(appMode string) func(http.Handler) http.Handler
- func GetLanguage(r *http.Request) i18n.Language
- func I18nMiddleware() func(http.Handler) http.Handler
- func IPWhitelistMiddleware(whitelist string) func(http.Handler) http.Handler
- func MetricsMiddleware(next http.Handler) http.Handler
- func SafeError(w http.ResponseWriter, r *http.Request, statusCode int, err error, ...)
- type ErrorResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorHandlerMiddleware ¶
ErrorHandlerMiddleware creates error handling middleware
This middleware hides detailed error information in production environment, only returning generic error messages. Detailed error information is only recorded in logs, not returned to clients.
Parameters:
- appMode: application mode ("production" or "prod" indicates production environment)
Returns:
- func(http.Handler) http.Handler: HTTP middleware function
func GetLanguage ¶ added in v0.2.0
GetLanguage gets language from request (helper function).
func I18nMiddleware ¶ added in v0.2.0
I18nMiddleware creates internationalization language detection middleware.
This middleware detects user language from HTTP requests with the following priority: 1. Query parameter ?lang=xx 2. Cookie 3. Accept-Language request header 4. Default language (English)
Detected language will be stored in request context for subsequent processing.
Returns:
- func(http.Handler) http.Handler: HTTP middleware function
func IPWhitelistMiddleware ¶
IPWhitelistMiddleware creates IP whitelist middleware.
This middleware only allows IP addresses in the whitelist to access protected endpoints. Whitelist is taken from the whitelist argument, or from environment variable IP_WHITELIST when whitelist is empty. Supports comma-separated multiple IPs or CIDR networks. Uses middleware-kit IPAllowlistMiddleware under the hood. Client IP is resolved via TrustedProxyConfig from TRUSTED_PROXY_IPS so behaviour matches other middleware-kit usage.
Parameters:
- whitelist: IP whitelist (comma-separated IP addresses or CIDR networks). Empty means use IP_WHITELIST env.
Returns:
- func(http.Handler) http.Handler: HTTP middleware function
func MetricsMiddleware ¶
MetricsMiddleware creates Prometheus metrics collection middleware
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
}
ErrorResponse error response structure