Documentation
¶
Index ¶
- Constants
- func Auth(parseToken TokenParser) func(http.Handler) http.Handler
- func Idempotency(store domain.IdempotencyStore) func(http.Handler) http.Handler
- func OTPRateLimiter(store domain.RateLimitStore, limit int, period time.Duration) func(http.Handler) http.Handler
- func Recovery(next 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 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 OTPRateLimiter ¶ added in v1.26.0
func OTPRateLimiter(store domain.RateLimitStore, limit int, period time.Duration) func(http.Handler) http.Handler
OTPRateLimiter returns a middleware that enforces per-email OTP rate limiting.
func Recovery ¶ added in v1.21.0
Recovery recovers from panics in handlers and renders a 500 internal server error page.
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.