middleware

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCSRFConfig = CSRFConfig{
	TokenHeader:    "X-CSRF-Token",
	TokenCookie:    "csrf_token",
	ContextKey:     "csrf_token",
	Expiry:         24 * time.Hour,
	Secret:         []byte("supersecretkey"),
	SkipMethods:    []string{http.MethodGet, http.MethodHead, http.MethodOptions, http.MethodTrace},
	CookieSecure:   true,
	CookieHTTPOnly: true,
}
View Source
var (
	ErrCSRFInvalid = errors.New("invalid CSRF token")
)

Functions

This section is empty.

Types

type CORSConfig

type CORSConfig struct {
	AllowOrigins []string
	AllowMethods []string
	AllowHeaders []string
}

CORSConfig defines allowed origins, headers, and methods.

type CSRFConfig

type CSRFConfig struct {
	TokenHeader    string        // header to read/write token
	TokenCookie    string        // cookie name
	ContextKey     string        // context key for token
	Expiry         time.Duration // token expiry
	Secret         []byte        // HMAC secret
	SkipMethods    []string      // methods that don't require validation
	ErrorHandler   func(*server.Context, error) *server.Response
	CookieSecure   bool
	CookieHTTPOnly bool
}

type ConditionalMiddleware

type ConditionalMiddleware struct {
	Pattern    string     // The URL path pattern to match, e.g., "/api/v1/*"
	Middleware Middleware // The middleware function to apply when the pattern matches
}

ConditionalMiddleware pairs a middleware with a path pattern. The middleware is only applied if the request path matches the pattern. Patterns can use a wildcard '*' at the end to match any subpath.

type Middleware

type Middleware func(server.HandlerFunc) server.HandlerFunc

Middleware defines the function signature for all middleware in OneStrike. A middleware wraps a HandlerFunc, allowing pre- or post-processing of requests. Example: logging, authentication, profiling, or panic recovery.

func CORS

func CORS() Middleware

CORS returns a middleware that sets CORS headers.

func CORSWithConfig

func CORSWithConfig(cfg CORSConfig) Middleware

CORSWithConfig returns a CORS middleware with custom configuration.

func CSRF

func CSRF() Middleware

CSRF returns middleware with default config

func CSRFWithConfig

func CSRFWithConfig(cfg CSRFConfig) Middleware

CSRFWithConfig returns middleware with custom config

func Logger

func Logger() Middleware

Logging

func ProfilingMiddleware

func ProfilingMiddleware() Middleware

ProfilingMiddleware logs detailed timing info including handler execution and memory usage

func Recovery

func Recovery() Middleware

Panic Recovery Recovery returns a middleware that recovers from panics and writes a 500 response.

Jump to

Keyboard shortcuts

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