middleware

package
v0.0.0-...-b26cdc7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware functions for the Mut application.

Package middleware provides HTTP middleware functions for the Tut application.

Index

Constants

View Source
const (
	// ContextKeyUser is the key for storing user in context
	ContextKeyUser contextKey = "user"
)

Context keys for storing user and session data

View Source
const RequestIDKey contextKey = "request_id"

RequestIDKey is the context key for storing request IDs

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(username, password string) func(http.Handler) http.Handler

BasicAuth creates a basic authentication middleware This is used for metrics endpoint

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID retrieves the request ID from the context

func GetUserFromContext

func GetUserFromContext(ctx context.Context) (*db.User, bool)

GetUserFromContext retrieves the user from the request context

func Logger

func Logger(next http.Handler) http.Handler

Logger creates a new logger middleware

func PrometheusMiddleware

func PrometheusMiddleware(next http.Handler) http.Handler

PrometheusMiddleware creates a middleware for Prometheus metrics

func RequestID

func RequestID(next http.Handler) http.Handler

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

func RequestSizeLimit(maxBytes int64) func(http.Handler) http.Handler

RequestSizeLimit creates a middleware that limits the size of request bodies maxBytes specifies the maximum allowed size in bytes

func RequireRole

func RequireRole(allowedRoles ...string) func(http.Handler) http.Handler

RequireRole creates a middleware that checks if the authenticated user has one of the required roles

func SessionAuth

func SessionAuth() func(http.Handler) http.Handler

SessionAuth creates a session-based authentication middleware It validates the session cookie and stores user/session in the request context

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL