middleware

package
v0.0.0-...-b09cb34 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0, AGPL-3.0-only Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogWebRequest

func LogWebRequest(c fiber.Ctx, startTime *time.Time, elapsedTime *time.Duration, disableSSRLogs bool, useColor bool, chainErr error)

func NewAccessLogger

func NewAccessLogger(logger *zap.Logger, disableSSRLogs bool, useColor bool) fiber.Handler

NewAccessLogger returns a middleware that logs requests and responses using the provided logger.

Pass disableSSRLogs=true to skip logging for SSR requests (useful in development)

func NewCachedETag

func NewCachedETag(config CachedETagConfig) fiber.Handler

NewCachedETag returns a middleware that reuses previously observed ETags and can short-circuit with 304 Not Modified before downstream response generation.

This middleware is intended to sit in front of Fiber's standard etag middleware, not replace it. On a cache miss it calls the next handler, captures the emitted ETag and related cache headers, and stores them in an in-memory cache scoped to this middleware instance. On a hit it compares the request's If-None-Match header against the cached ETag and returns 304 before downstream handlers run.

The cache is keyed by CachedETagResource.Key and guarded by CachedETagResource.Version. If the version changes, the cached validator is treated as stale and the downstream chain is allowed to regenerate the response and its ETag.

Types

type CachedETagConfig

type CachedETagConfig struct {
	// Next skips the middleware when it returns true.
	Next func(c fiber.Ctx) bool
	// Resolve identifies the cacheable resource for the current request.
	Resolve CachedETagResolver
}

CachedETagConfig configures NewCachedETag.

type CachedETagResolver

type CachedETagResolver func(c fiber.Ctx) (CachedETagResource, bool)

CachedETagResolver resolves the logical resource behind the current request.

Returning ok=false skips this middleware for the request.

type CachedETagResource

type CachedETagResource struct {
	Key     string
	Version string
}

CachedETagResource identifies a cacheable downstream response.

Key must be stable for the logical resource across requests, while Version must change whenever that resource's body would produce a different ETag. Together they let the middleware reuse a previously emitted validator without keying the cache directly by request URL.

Jump to

Keyboard shortcuts

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