middleware

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 8 Imported by: 2 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

Overview

Package middleware provides HTTP middleware shared between AI Studio and the Microgateway.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MetricsBearerAuth

func MetricsBearerAuth(token string) gin.HandlerFunc

MetricsBearerAuth returns middleware that requires "Authorization: Bearer <token>" on the metrics endpoint. Token comparison is constant-time.

func Recovery added in v2.3.0

func Recovery() gin.HandlerFunc

Recovery answers 500 when a handler panics. Unlike gin.Recovery, which dumps the request headers (masking only Authorization), it logs the method, route template, request id, panic value and stack only: headers carry cookies, API keys and end-user identity (X-Tyk-User-Id, baggage).

func RegisterMetricsEndpoint

func RegisterMetricsEndpoint(router gin.IRoutes, cfg MetricsEndpointConfig) bool

RegisterMetricsEndpoint mounts the metrics handler with secure defaults:

  • AuthToken set: endpoint requires a matching bearer token
  • AllowUnauthenticated true: endpoint is served without auth
  • neither: endpoint is not registered at all

Returns true if the endpoint was registered.

Types

type MetricsEndpointConfig

type MetricsEndpointConfig struct {
	// Path is the route path the handler is mounted on, e.g. "/metrics".
	Path string
	// Handler serves the metrics (typically a Prometheus handler). If nil,
	// the endpoint is not registered.
	Handler http.Handler
	// AuthToken, when non-empty, protects the endpoint with bearer auth.
	AuthToken string
	// AllowUnauthenticated serves the endpoint without auth when no token is
	// set (e.g. for in-cluster Prometheus scraping behind a network boundary).
	AllowUnauthenticated bool
	// Warn, if non-nil, is called with security-relevant warnings so each
	// service can route them through its own logger.
	Warn func(msg string)
}

MetricsEndpointConfig configures RegisterMetricsEndpoint.

Jump to

Keyboard shortcuts

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