Documentation
¶
Overview ¶
Package middleware provides HTTP middleware functions for the Mut application.
Package middleware provides HTTP middleware functions for the Tut application.
Index ¶
- Constants
- func BasicAuth(username, password string) func(http.Handler) http.Handler
- func GetRequestID(ctx context.Context) string
- func GetUserFromContext(ctx context.Context) (*db.User, bool)
- func Logger(next http.Handler) http.Handler
- func PrometheusMiddleware(next http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func RequestSizeLimit(maxBytes int64) func(http.Handler) http.Handler
- func RequireRole(allowedRoles ...string) func(http.Handler) http.Handler
- func SessionAuth() func(http.Handler) http.Handler
Constants ¶
const (
// ContextKeyUser is the key for storing user in context
ContextKeyUser contextKey = "user"
)
Context keys for storing user and session data
const RequestIDKey contextKey = "request_id"
RequestIDKey is the context key for storing request IDs
Variables ¶
This section is empty.
Functions ¶
func BasicAuth ¶
BasicAuth creates a basic authentication middleware This is used for metrics endpoint
func GetRequestID ¶
GetRequestID retrieves the request ID from the context
func GetUserFromContext ¶
GetUserFromContext retrieves the user from the request context
func PrometheusMiddleware ¶
PrometheusMiddleware creates a middleware for Prometheus metrics
func RequestID ¶
RequestID middleware adds a unique request ID to each request It checks for existing X-Request-ID header, or generates a new UUID
func RequestSizeLimit ¶
RequestSizeLimit creates a middleware that limits the size of request bodies maxBytes specifies the maximum allowed size in bytes
func RequireRole ¶
RequireRole creates a middleware that checks if the authenticated user has one of the required roles
Types ¶
This section is empty.