middleware

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package middleware provides Hockeypuck-compatible middleware patterns This ensures plugins work seamlessly with interpose middleware chains

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MetricsMiddleware

func MetricsMiddleware(pluginName string, logger *log.Logger) func(http.Handler) http.Handler

MetricsMiddleware provides request metrics

func SecurityMiddleware

func SecurityMiddleware(pluginName string) func(http.Handler) http.Handler

SecurityMiddleware provides common security patterns

Types

type InterposePriority

type InterposePriority int

InterposePriority defines middleware execution order

const (
	// High priority - runs first (security, auth)
	PriorityHigh InterposePriority = 100

	// Medium priority - runs in middle (rate limiting, validation)
	PriorityMedium InterposePriority = 50

	// Low priority - runs last (logging, metrics)
	PriorityLow InterposePriority = 10
)

type Middleware

type Middleware struct {
	Name     string
	Priority InterposePriority
	Handler  func(http.Handler) http.Handler
	Path     string // Path pattern this middleware applies to
}

Middleware represents a plugin middleware with priority

type MiddlewareChain

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

MiddlewareChain manages ordered middleware execution compatible with interpose

func NewMiddlewareChain

func NewMiddlewareChain(logger *log.Logger) *MiddlewareChain

NewMiddlewareChain creates a new middleware chain

func (*MiddlewareChain) Add

func (mc *MiddlewareChain) Add(middleware Middleware)

Add adds middleware to the chain

func (*MiddlewareChain) Build

func (mc *MiddlewareChain) Build() func(http.Handler) http.Handler

Build creates the final middleware handler compatible with interpose

func (*MiddlewareChain) GetMiddlewares

func (mc *MiddlewareChain) GetMiddlewares() []Middleware

GetMiddlewares returns all registered middlewares for inspection

type PathMatcher

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

PathMatcher provides path-based middleware application

func NewPathMatcher

func NewPathMatcher(logger *log.Logger) *PathMatcher

NewPathMatcher creates a new path matcher

func (*PathMatcher) AddPath

func (pm *PathMatcher) AddPath(pattern string, middleware func(http.Handler) http.Handler)

AddPath adds a path-specific middleware

func (*PathMatcher) Middleware

func (pm *PathMatcher) Middleware() func(http.Handler) http.Handler

Middleware returns a middleware that applies path-specific handlers

type PluginMiddlewareWrapper

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

PluginMiddlewareWrapper wraps plugin middleware for interpose compatibility

func NewPluginMiddlewareWrapper

func NewPluginMiddlewareWrapper(pluginName string, logger *log.Logger) *PluginMiddlewareWrapper

NewPluginMiddlewareWrapper creates a wrapper for plugin middleware

func (*PluginMiddlewareWrapper) WrapMiddleware

func (pmw *PluginMiddlewareWrapper) WrapMiddleware(
	middleware func(http.Handler) http.Handler,
	priority InterposePriority,
) func(http.Handler) http.Handler

WrapMiddleware wraps plugin middleware with logging and error handling

Jump to

Keyboard shortcuts

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