Documentation
¶
Index ¶
- Constants
- func ConfigureRateLimiter(r chi.Router, cfg RateLimitConfig)
- func ConfigureRateLimiterFromConfig(r chi.Router, cfg *config.RateLimitConfig, scope RateLimitScope, ...)
- func HealthzHandler() http.Handler
- func OapiErrorHandler(w http.ResponseWriter, message string, statusCode int)
- func ReadyzHandler(timeout time.Duration, checks ...HealthChecker) http.Handler
- type HealthChecker
- type RateLimitConfig
- type RateLimitDefaults
- type RateLimitOption
- type RateLimitScope
- type RateLimitScopeDefaults
- type Server
Constants ¶
const GracefulShutdownTimeout = 5 * time.Second
GracefulShutdownTimeout is the duration to wait for graceful shutdown
Variables ¶
This section is empty.
Functions ¶
func ConfigureRateLimiter ¶
func ConfigureRateLimiter(r chi.Router, cfg RateLimitConfig)
ConfigureRateLimiter adds rate limiting to a router with the given config
func ConfigureRateLimiterFromConfig ¶
func ConfigureRateLimiterFromConfig( r chi.Router, cfg *config.RateLimitConfig, scope RateLimitScope, options ...RateLimitOption, )
ConfigureRateLimiterFromConfig applies rate limiting based on service config. If trustedProxies is unset, it falls back to cfg.TrustedProxies.
func HealthzHandler ¶ added in v0.10.0
HealthzHandler returns a simple HTTP handler that always returns OK. This is for liveness probes that just need to know if the process is running. The response body is empty.
func OapiErrorHandler ¶
func OapiErrorHandler(w http.ResponseWriter, message string, statusCode int)
OapiErrorHandler is a shared error handler for OpenAPI validation errors
func ReadyzHandler ¶ added in v0.10.0
func ReadyzHandler(timeout time.Duration, checks ...HealthChecker) http.Handler
ReadyzHandler returns a simple HTTP handler that runs health checks. It iterates through provided checks and returns 503 on any failure. The response body is empty.
Types ¶
type HealthChecker ¶ added in v0.10.0
HealthChecker is a minimal contract for readiness checks.
type RateLimitConfig ¶
type RateLimitConfig struct {
Requests int
Window time.Duration
TrustedProxies []string
Message string
}
RateLimitConfig holds rate limiting parameters
type RateLimitDefaults ¶
type RateLimitOption ¶
type RateLimitOption func(*rateLimitOptions)
func WithMessage ¶
func WithMessage(message string) RateLimitOption
func WithNoTrustedProxies ¶
func WithNoTrustedProxies() RateLimitOption
func WithRate ¶
func WithRate(defaults RateLimitDefaults) RateLimitOption
func WithTrustedProxies ¶
func WithTrustedProxies(trustedProxies []string) RateLimitOption
type RateLimitScope ¶
type RateLimitScope int
const ( RateLimitScopeGeneral RateLimitScope = iota RateLimitScopeAuth )
type RateLimitScopeDefaults ¶
type RateLimitScopeDefaults struct {
Defaults RateLimitDefaults
Message string
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}