middleware

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package middleware provides HTTP and gRPC middleware for the Sparrow server.

Index

Constants

View Source
const (
	// APIKeyHeader is the HTTP header used to pass the API key.
	APIKeyHeader = "X-API-Key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyAuth

type APIKeyAuth struct {
	// APIKey is the expected key. Empty means authentication is disabled.
	APIKey string

	// ExcludedPathPrefixes are HTTP path prefixes that bypass authentication
	// (e.g., "/health", "/ready", static UI assets).
	ExcludedPathPrefixes []string
}

APIKeyAuth holds the configuration for API key authentication. When APIKey is empty, all requests are allowed through (no-op mode).

func (*APIKeyAuth) Enabled

func (a *APIKeyAuth) Enabled() bool

Enabled reports whether API key authentication is active.

func (*APIKeyAuth) HTTPMiddleware

func (a *APIKeyAuth) HTTPMiddleware(next http.Handler) http.Handler

HTTPMiddleware returns an http.Handler that enforces API key authentication. When the API key is not configured (empty), requests pass through unchanged.

The key can be provided via:

  • Header: X-API-Key: <key>
  • Query parameter: ?api_key=<key> (useful for browser/curl convenience)

Excluded paths (health, ready, static UI files) are never checked.

func (*APIKeyAuth) StreamServerInterceptor

func (a *APIKeyAuth) StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a gRPC stream interceptor that enforces API key authentication via the "x-api-key" metadata header.

func (*APIKeyAuth) UnaryServerInterceptor

func (a *APIKeyAuth) UnaryServerInterceptor() grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a gRPC unary interceptor that enforces API key authentication via the "x-api-key" metadata header. When the API key is not configured (empty), requests pass through unchanged.

Jump to

Keyboard shortcuts

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