middleware

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

README

middleware

import "github.com/agentstation/starmap/internal/server/middleware"

Package middleware provides HTTP middleware for the Starmap API server. It includes logging, recovery, CORS, authentication, and rate limiting.

Index

func Auth

func Auth(config AuthConfig, logger *zerolog.Logger) func(http.Handler) http.Handler

Auth middleware validates API keys for protected endpoints.

func CORS

func CORS(config CORSConfig) func(http.Handler) http.Handler

CORS middleware adds CORS headers to responses.

func Chain

func Chain(middlewares ...func(http.Handler) http.Handler) func(http.Handler) http.Handler

Chain combines multiple middleware functions into a single middleware.

func Logger

func Logger(logger *zerolog.Logger) func(http.Handler) http.Handler

Logger logs HTTP requests with structured logging.

func RateLimit

func RateLimit(rl *RateLimiter) func(http.Handler) http.Handler

RateLimit middleware limits requests per IP address.

func Recovery

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

Recovery recovers from panics and returns 500 error.

type AuthConfig

AuthConfig holds authentication configuration.

type AuthConfig struct {
    Enabled      bool
    APIKey       string
    HeaderName   string
    PublicPaths  []string
    BearerPrefix bool
}

func DefaultAuthConfig
func DefaultAuthConfig() AuthConfig

DefaultAuthConfig returns default authentication configuration.

type CORSConfig

CORSConfig holds CORS configuration.

type CORSConfig struct {
    AllowedOrigins []string
    AllowedMethods []string
    AllowedHeaders []string
    AllowAll       bool
}

func DefaultCORSConfig
func DefaultCORSConfig() CORSConfig

DefaultCORSConfig returns the default CORS configuration.

type RateLimiter

RateLimiter implements token bucket rate limiting per IP address.

type RateLimiter struct {
    // contains filtered or unexported fields
}

func NewRateLimiter
func NewRateLimiter(limit int, logger *zerolog.Logger) *RateLimiter

NewRateLimiter creates a new rate limiter. limit is requests per minute per IP.

Generated by gomarkdoc

Documentation

Overview

Package middleware provides HTTP middleware for the Starmap API server. It includes logging, recovery, CORS, authentication, and rate limiting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(config AuthConfig, logger *zerolog.Logger) func(http.Handler) http.Handler

Auth middleware validates API keys for protected endpoints.

func CORS

func CORS(config CORSConfig) func(http.Handler) http.Handler

CORS middleware adds CORS headers to responses.

func Chain

func Chain(middlewares ...func(http.Handler) http.Handler) func(http.Handler) http.Handler

Chain combines multiple middleware functions into a single middleware.

func Logger

func Logger(logger *zerolog.Logger) func(http.Handler) http.Handler

Logger logs HTTP requests with structured logging.

func RateLimit

func RateLimit(rl *RateLimiter) func(http.Handler) http.Handler

RateLimit middleware limits requests per IP address.

func Recovery

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

Recovery recovers from panics and returns 500 error.

Types

type AuthConfig

type AuthConfig struct {
	Enabled      bool
	APIKey       string
	HeaderName   string
	PublicPaths  []string
	BearerPrefix bool
}

AuthConfig holds authentication configuration.

func DefaultAuthConfig

func DefaultAuthConfig() AuthConfig

DefaultAuthConfig returns default authentication configuration.

type CORSConfig

type CORSConfig struct {
	AllowedOrigins []string
	AllowedMethods []string
	AllowedHeaders []string
	AllowAll       bool
}

CORSConfig holds CORS configuration.

func DefaultCORSConfig

func DefaultCORSConfig() CORSConfig

DefaultCORSConfig returns the default CORS configuration.

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter implements token bucket rate limiting per IP address.

func NewRateLimiter

func NewRateLimiter(limit int, logger *zerolog.Logger) *RateLimiter

NewRateLimiter creates a new rate limiter. limit is requests per minute per IP.

Jump to

Keyboard shortcuts

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