Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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, }
var (
ErrCSRFInvalid = errors.New("invalid CSRF token")
)
Functions ¶
This section is empty.
Types ¶
type CORSConfig ¶
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 CORSWithConfig ¶
func CORSWithConfig(cfg CORSConfig) Middleware
CORSWithConfig returns a CORS middleware with custom configuration.
func CSRFWithConfig ¶
func CSRFWithConfig(cfg CSRFConfig) Middleware
CSRFWithConfig returns middleware with custom config
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.