middleware

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// RequestIDHeader is the HTTP header name for request IDs
	RequestIDHeader = "X-Request-Id"
)

Variables

This section is empty.

Functions

func ChunkedEncoding

func ChunkedEncoding(decoderFactory ChunkedDecoderFactory) func(http.Handler) http.Handler

ChunkedEncoding is a middleware that decodes AWS SigV4 chunked transfer encoding if present in the request body. It should run AFTER authentication middleware.

This middleware: - Checks multiple indicators for AWS SigV4 chunked encoding - If detected, wraps r.Body with a decoder provided by the factory - The handler receives the decoded body transparently - Applies to all operations that accept request bodies (PutObject, UploadPart, etc.)

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID extracts the request ID from the context. Returns an empty string if no request ID is found.

func GetRequestStartTime

func GetRequestStartTime(ctx context.Context) (time.Time, bool)

GetRequestStartTime retrieves the request start time from context. Returns the time and true if found, or zero time and false if not found.

func RequestID

func RequestID(next http.Handler) http.Handler

RequestID is a middleware that generates a unique request ID for each request. It adds the request ID to the request context and optionally to the response headers.

func SetDefaultHeadersMiddleware

func SetDefaultHeadersMiddleware(next http.Handler) http.Handler

SetDefaultHeadersMiddleware is a middleware that sets a specific header

func Timing

func Timing(next http.Handler) http.Handler

Timing is a middleware that captures the request start time as early as possible. This should be the FIRST middleware in the chain to get the most accurate timestamp of when the server received the request.

func TraceID

func TraceID(next http.Handler) http.Handler

TraceID is a middleware that generates or accepts a trace ID for each request. This is the first middleware that should run, creating the trace context for the entire request lifecycle. It checks for an incoming X-Trace-ID header and uses it if present, otherwise generates a new one.

func ValidateS3BucketName

func ValidateS3BucketName(bucket string) error

ValidateS3BucketName validates a bucket name according to S3 naming rules.

S3 bucket naming rules: - Between 3 and 63 characters long - Consist only of lowercase letters, numbers, dots (.), and hyphens (-) - Begin and end with a letter or number - Must not contain two adjacent periods - Must not be formatted as an IP address (e.g., 192.168.5.4)

func ValidateS3BucketNameMiddleware

func ValidateS3BucketNameMiddleware(
	getBucket func(*http.Request) string,
	writeError response.XMLErrorWriter,
) func(http.Handler) http.Handler

ValidateS3BucketNameMiddleware returns a middleware that validates S3 bucket names. It should be applied to routes that have a {bucket} parameter. If validation fails, it writes an error response and stops the request chain.

The getBucket function extracts the bucket name from the request (typically from URL params). The writeError function handles writing the S3-formatted error response.

func ValidateS3Key

func ValidateS3Key(key string) error

ValidateS3Key validates an object key according to S3 naming rules.

S3 key naming rules: - Can be up to 1024 bytes long (UTF-8 encoded) - Can contain any UTF-8 character - Should avoid certain characters that require special handling - Must not start with '/' (not a valid S3 key)

func ValidateS3KeyMiddleware

func ValidateS3KeyMiddleware(
	getKey func(*http.Request) string,
	writeError response.XMLErrorWriter,
) func(http.Handler) http.Handler

ValidateS3KeyMiddleware returns a middleware that validates S3 object keys. It should be applied to routes that have a {key} parameter. If validation fails, it writes an error response and stops the request chain.

The getKey function extracts the key from the request (typically from URL params). The writeError function handles writing the S3-formatted error response.

Types

type ChunkedDecoderFactory

type ChunkedDecoderFactory func(io.Reader) io.Reader

ChunkedDecoderFactory creates chunked readers - injected to avoid import cycles

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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