middleware

package
v0.0.56 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

README

middleware

Shared Gin HTTP middleware for the API server. Intended to be reusable if a Go frontend is ever added alongside the API. Currently provides three middleware handlers that are applied globally to the router.

Panic recovery sits first in the middleware chain. It defers a recover call around every request, so if a route handler panics, the server logs the error with the path, method, and client IP, then responds with a 500 status instead of crashing. Stack trace inclusion is configurable. Request logging runs after each request completes and records method, path, status code, raw duration in nanoseconds, and a human-readable duration (auto-scaled to microseconds, milliseconds, or seconds) along with user agent and client IP, all as a structured debug log entry. CORS handling allows all origins, methods, and headers including WebSocket upgrades; this is intentionally permissive and should be restricted before any production deployment.

Documentation

Overview

Package middleware implements some common gin middleware that can be shared between the API and a potential golang frontend. Includes panic recovery and request logging. Request logs contain both a raw duration (for machine parsing) and a human-readable pretty_duration field.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsecureCORS

func InsecureCORS() gin.HandlerFunc

InsecureCORS is a middleware that responds to option headers allowing all origins, methods, and headers. This should be replaces with a secure set up for production.

func Logging

func Logging() gin.HandlerFunc

Logging is a middleware that tracks request information. It shows how long requests take, as well as some other information.

func Recovery

func Recovery(includeStackTrace bool) gin.HandlerFunc

Recovery is the first middleware in the chain. It recovers from panics that happen in routes. There is a default one but it has ugly logging. Without this middleware, every panic in a route would crash the entire server.

Types

This section is empty.

Jump to

Keyboard shortcuts

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