Documentation
¶
Index ¶
- func CORS(config CORSConfig) forge.Middleware
- func Compress(level int) forge.Middleware
- func CompressDefault() forge.Middleware
- func GetRequestID(ctx context.Context) string
- func Logging(logger forge.Logger) forge.Middleware
- func LoggingWithConfig(logger forge.Logger, config LoggingConfig) forge.Middleware
- func RateLimit(limiter *RateLimiter, logger forge.Logger) forge.Middleware
- func Recovery(logger forge.Logger) forge.Middleware
- func RequestID() forge.Middleware
- func Timeout(duration time.Duration, logger forge.Logger) forge.Middleware
- type CORSConfig
- type LoggingConfig
- type RateLimiter
- type RequestIDContextKey
- type ResponseWriter
- func (w *ResponseWriter) Flush()
- func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *ResponseWriter) Push(target string, opts *http.PushOptions) error
- func (w *ResponseWriter) Size() int
- func (w *ResponseWriter) Status() int
- func (w *ResponseWriter) Write(data []byte) (int, error)
- func (w *ResponseWriter) WriteHeader(code int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORS ¶
func CORS(config CORSConfig) forge.Middleware
CORS returns middleware that handles Cross-Origin Resource Sharing
func Compress ¶
func Compress(level int) forge.Middleware
Compress middleware compresses HTTP responses using gzip Only compresses if client supports gzip and response is suitable for compression
func CompressDefault ¶
func CompressDefault() forge.Middleware
CompressDefault returns Compress middleware with default compression level
func GetRequestID ¶
GetRequestID retrieves the request ID from context
func Logging ¶
func Logging(logger forge.Logger) forge.Middleware
Logging middleware logs HTTP requests with timing information
func LoggingWithConfig ¶
func LoggingWithConfig(logger forge.Logger, config LoggingConfig) forge.Middleware
LoggingWithConfig middleware logs HTTP requests with custom configuration
func RateLimit ¶
func RateLimit(limiter *RateLimiter, logger forge.Logger) forge.Middleware
RateLimit middleware enforces rate limiting per client
func Recovery ¶
func Recovery(logger forge.Logger) forge.Middleware
Recovery middleware recovers from panics and logs them Returns 500 Internal Server Error on panic
func RequestID ¶
func RequestID() forge.Middleware
RequestID middleware adds a unique request ID to each request If X-Request-ID header is present, it uses that, otherwise generates a new UUID
Types ¶
type CORSConfig ¶
type CORSConfig struct {
// AllowOrigin defines the allowed origin(s)
// Use "*" for all origins, or specific origin like "https://example.com"
AllowOrigin string
// AllowMethods defines allowed HTTP methods
AllowMethods []string
// AllowHeaders defines allowed request headers
AllowHeaders []string
// ExposeHeaders defines headers exposed to the client
ExposeHeaders []string
// AllowCredentials indicates whether credentials are allowed
AllowCredentials bool
// MaxAge indicates how long preflight requests can be cached (seconds)
MaxAge int
}
CORSConfig defines configuration for CORS middleware
func DefaultCORSConfig ¶
func DefaultCORSConfig() CORSConfig
DefaultCORSConfig returns a permissive CORS configuration suitable for development
type LoggingConfig ¶
type LoggingConfig struct {
// IncludeHeaders includes request headers in logs
IncludeHeaders bool
// ExcludePaths defines paths to exclude from logging
ExcludePaths []string
// SensitiveHeaders defines headers to redact in logs
SensitiveHeaders []string
}
LoggingConfig defines configuration for logging middleware
func DefaultLoggingConfig ¶
func DefaultLoggingConfig() LoggingConfig
DefaultLoggingConfig returns default logging configuration
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements token bucket algorithm for rate limiting
func NewRateLimiter ¶
func NewRateLimiter(rate, burst int) *RateLimiter
NewRateLimiter creates a new rate limiter rate: maximum requests per second burst: maximum burst size (capacity)
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(key string) bool
Allow checks if a request from the given key should be allowed
type RequestIDContextKey ¶
type RequestIDContextKey string
RequestIDContextKey is the context key for storing request ID
type ResponseWriter ¶
type ResponseWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
ResponseWriter wraps http.ResponseWriter to capture status code and size
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter) *ResponseWriter
NewResponseWriter creates a new ResponseWriter
func (*ResponseWriter) Hijack ¶
func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements http.Hijacker
func (*ResponseWriter) Push ¶
func (w *ResponseWriter) Push(target string, opts *http.PushOptions) error
Push implements http.Pusher
func (*ResponseWriter) Size ¶
func (w *ResponseWriter) Size() int
Size returns the response size in bytes
func (*ResponseWriter) Status ¶
func (w *ResponseWriter) Status() int
Status returns the HTTP status code
func (*ResponseWriter) Write ¶
func (w *ResponseWriter) Write(data []byte) (int, error)
Write writes data and captures size
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(code int)
WriteHeader captures the status code