Documentation
¶
Index ¶
- Constants
- func AccessLog(log *slog.Logger, next http.Handler) http.Handler
- func CircuitBreak(b *CircuitBreaker, next http.Handler) http.Handler
- func ConcurrencyLimit(sem *Semaphore, next http.Handler) http.Handler
- func Instrument(m *Metrics, next http.Handler) http.Handler
- func MaxBodyBytes(limit int64, next http.Handler) http.Handler
- func OptionalAuth(auth AuthHandler, next http.Handler) http.Handler
- func RID(ctx context.Context) string
- func RateLimit(limiter ratelimit.Limiter, ipr IPResolver, cfg RateLimitConfig, ...) http.Handler
- func Recover(next http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func RequireAdminKey(adminKey string, next http.Handler) http.Handler
- func RequireAuth(auth AuthHandler, next http.Handler) http.Handler
- func RouteName(ctx context.Context) string
- func Subject(ctx context.Context) (string, bool)
- func WithRoute(next http.Handler, routeName string) http.Handler
- func WithSubject(next http.Handler, sub string) http.Handler
- type AuthHandler
- type Authenticator
- type BreakerConfig
- type BreakerState
- type BreakerStats
- type CircuitBreaker
- type IPResolver
- type JWKSStats
- type JWKSValidator
- type JWKSValidatorOptions
- type Metrics
- type RateLimitConfig
- type Semaphore
Constants ¶
View Source
const AdminKeyHeader = "X-Admin-Key"
Variables ¶
This section is empty.
Functions ¶
func CircuitBreak ¶
func CircuitBreak(b *CircuitBreaker, next http.Handler) http.Handler
CircuitBreak rejects requests when the breaker is open. It counts failures when downstream returns >= 500.
func ConcurrencyLimit ¶
ConcurrencyLimit rejects requests when too many are already in-flight for a route.
func OptionalAuth ¶
func OptionalAuth(auth AuthHandler, next http.Handler) http.Handler
func RateLimit ¶
func RateLimit(limiter ratelimit.Limiter, ipr IPResolver, cfg RateLimitConfig, next http.Handler) http.Handler
func RequireAuth ¶
func RequireAuth(auth AuthHandler, next http.Handler) http.Handler
Types ¶
type Authenticator ¶
type Authenticator struct {
Mode string // "hmac" | "jwks"
HMACSecret []byte
JWKS *JWKSValidator
}
func (Authenticator) ValidateBearer ¶
func (a Authenticator) ValidateBearer(r *http.Request) (string, error)
type BreakerConfig ¶
type BreakerState ¶
type BreakerState string
const ( BreakerClosed BreakerState = "closed" BreakerOpen BreakerState = "open" BreakerHalfOpen BreakerState = "half_open" )
type BreakerStats ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
func NewCircuitBreaker ¶
func NewCircuitBreaker(cfg BreakerConfig) *CircuitBreaker
func (*CircuitBreaker) Stats ¶
func (b *CircuitBreaker) Stats() BreakerStats
type IPResolver ¶
type JWKSValidator ¶
type JWKSValidator struct {
// contains filtered or unexported fields
}
JWKSValidator validates RS256 JWTs using a remote JWKS. It caches public keys by kid and refreshes on cache-expiry or unknown kid.
func NewJWKSValidator ¶
func NewJWKSValidator(url string, opts JWKSValidatorOptions) (*JWKSValidator, error)
func (*JWKSValidator) Stats ¶
func (j *JWKSValidator) Stats() JWKSStats
type JWKSValidatorOptions ¶
type JWKSValidatorOptions struct {
HTTPTimeout time.Duration
CacheTTL time.Duration
Leeway time.Duration
// If provided, token must match one of these issuers.
Issuers []string
// If provided, token must match one of these audiences.
Audiences []string
// Allowed JWT algs (default ["RS256"])
ValidAlgs []string
}
type Metrics ¶
type Metrics struct {
Requests *prometheus.CounterVec
Latency *prometheus.HistogramVec
}
func NewMetrics ¶
func NewMetrics(reg prometheus.Registerer) *Metrics
type RateLimitConfig ¶
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore is a tiny counting semaphore for per-route in-flight limiting.
func NewSemaphore ¶
func (*Semaphore) TryAcquire ¶
Click to show internal directories.
Click to hide internal directories.