Documentation
¶
Index ¶
- Constants
- func Auth(parseToken TokenParser) func(http.Handler) http.Handler
- func Idempotency(store domain.IdempotencyStore) func(http.Handler) http.Handler
- func RequestLogger() func(http.Handler) http.Handler
- func RequireAuth(parseToken TokenParser) func(http.Handler) http.Handler
- func RequireRole(roles ...domain.Role) func(http.Handler) http.Handler
- func RoleFromCtx(ctx context.Context) (string, bool)
- func TenantIDFromCtx(ctx context.Context) (string, bool)
- func UserIDFromCtx(ctx context.Context) (string, bool)
- type ErrorResponse
- type RateLimiterStore
- type TokenParser
Constants ¶
const ( TenantIDKey contextKey = iota UserIDKey RoleKey )
Variables ¶
This section is empty.
Functions ¶
func Auth ¶
func Auth(parseToken TokenParser) func(http.Handler) http.Handler
Auth is the middleware that validates the JWT and adds the user_id and tenant_id to the context.
func Idempotency ¶
Idempotency middleware ensures that POST requests are processed at most once by caching the response associated with a specific Idempotency-Key.
func RequestLogger ¶
RequestLogger returns a middleware that logs each request as a structured slog entry.
func RequireAuth ¶
func RequireAuth(parseToken TokenParser) func(http.Handler) http.Handler
RequireAuth is an alias for Auth to satisfy existing calls.
func RequireRole ¶
RequireRole is a middleware that ensures the user has one of the required roles.
func RoleFromCtx ¶
RoleFromCtx extracts the user role from the context.
func TenantIDFromCtx ¶
TenantIDFromCtx extracts the tenant ID from the context.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"error"`
}
ErrorResponse represents the JSON body returned for authentication and authorization errors.
type RateLimiterStore ¶
type RateLimiterStore struct {
// contains filtered or unexported fields
}
RateLimiterStore holds the state for the in-memory rate limiters.
func NewRateLimiterStore ¶
func NewRateLimiterStore() *RateLimiterStore
NewRateLimiterStore creates a new store and starts the cleanup goroutine.
func NewRateLimiterStoreWithInterval ¶
func NewRateLimiterStoreWithInterval(interval time.Duration) *RateLimiterStore
NewRateLimiterStoreWithInterval is for testing cleanup with custom intervals.
func (*RateLimiterStore) Close ¶
func (s *RateLimiterStore) Close()
Close stops the cleanup goroutine.
func (*RateLimiterStore) OTPRateLimiter ¶
func (s *RateLimiterStore) OTPRateLimiter() func(http.Handler) http.Handler
OTPRateLimiter returns a middleware that enforces per-email OTP rate limiting.