middleware

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestIDHeader is the header name for request ID
	RequestIDHeader = "X-Request-ID"
)
View Source
const (
	// RequestIDKey is the context key for request ID
	RequestIDKey contextKey = "request_id"
)

Variables

This section is empty.

Functions

func CORS

func CORS() gin.HandlerFunc

CORS creates a CORS middleware with default configuration

func CORSWithConfig

func CORSWithConfig(config CORSConfig) gin.HandlerFunc

CORSWithConfig creates a CORS middleware with custom configuration

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID extracts the request ID from the context

func Logger

func Logger(logger *slog.Logger) gin.HandlerFunc

Logger creates a structured logging middleware using slog

func LoggerWithConfig

func LoggerWithConfig(logger *slog.Logger, config gin.LoggerConfig) gin.HandlerFunc

LoggerWithConfig creates a structured logging middleware with custom configuration

func RequestID

func RequestID() gin.HandlerFunc

RequestID middleware adds a unique request ID to each request

Types

type CORSConfig

type CORSConfig struct {
	AllowOrigins     []string
	AllowMethods     []string
	AllowHeaders     []string
	ExposeHeaders    []string
	AllowCredentials bool
	MaxAge           int
}

CORSConfig holds CORS configuration

func DefaultCORSConfig

func DefaultCORSConfig() CORSConfig

DefaultCORSConfig returns a default CORS configuration suitable for GraphQL

Jump to

Keyboard shortcuts

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