middleware

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for the PeeringDB Plus server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(in CORSInput) func(http.Handler) http.Handler

CORS returns middleware that adds CORS headers per OPS-06. Origins are configured via the AllowedOrigins field.

func Caching added in v1.9.0

func Caching(in CachingInput) func(http.Handler) http.Handler

Caching returns middleware that sets Cache-Control and ETag headers on GET/HEAD responses, and returns 304 Not Modified for conditional requests when data has not changed since the last sync.

Only GET and HEAD methods receive caching headers. POST and other mutation methods pass through unchanged. If no successful sync has occurred (zero sync time), no caching headers are set.

func Logging

func Logging(logger *slog.Logger) func(http.Handler) http.Handler

Logging returns middleware that logs each HTTP request with method, path, status, duration, and trace context (trace_id, span_id) when available. Uses structured slog per OBS-1, OBS-5 with LogAttrs for attribute-based API.

func Recovery

func Recovery(logger *slog.Logger) func(http.Handler) http.Handler

Recovery returns middleware that recovers from panics in downstream handlers. Logs the panic with stack trace via slog and returns 500 to the client.

Types

type CORSInput

type CORSInput struct {
	// AllowedOrigins is a comma-separated list of allowed origins. Use "*" for all origins.
	AllowedOrigins string
}

CORSInput holds configuration for the CORS middleware.

type CachingInput added in v1.9.0

type CachingInput struct {
	// SyncTimeFn returns the last successful sync completion time.
	// Returns zero time if no successful sync has occurred.
	SyncTimeFn func() time.Time

	// SyncInterval is the configured duration between automatic sync runs.
	// Used to calculate Cache-Control max-age (interval + 120s buffer).
	SyncInterval time.Duration
}

CachingInput holds configuration for the HTTP caching middleware.

Jump to

Keyboard shortcuts

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