Documentation
¶
Overview ¶
Package skip conditionally bypasses middleware.
It is useful when middleware should not run for health checks, public routes, CORS preflights, static assets, specific methods, or custom request rules.
Example:
app.Use(skip.New(csrf.New(), skip.Any(
skip.Paths("/health", "/csrf-token"),
skip.Methods("GET", "HEAD", "OPTIONS"),
)))
Index ¶
- func New(middleware fh.HandlerFunc, predicate Predicate) fh.HandlerFunc
- func NewWithConfig(middleware fh.HandlerFunc, cfg Config) fh.HandlerFunc
- type Config
- type Logic
- type Predicate
- func All(predicates ...Predicate) Predicate
- func Always() Predicate
- func Any(predicates ...Predicate) Predicate
- func Contains(parts ...string) Predicate
- func Custom(p Predicate) Predicate
- func Globs(patterns ...string) Predicate
- func HeaderContains(name, value string) Predicate
- func HeaderEquals(name, value string) Predicate
- func HeaderExists(name string) Predicate
- func HeaderPrefix(name, prefix string) Predicate
- func HeaderSuffix(name, suffix string) Predicate
- func Health() Predicate
- func Methods(methods ...string) Predicate
- func Never() Predicate
- func Not(p Predicate) Predicate
- func PathCI(paths ...string) Predicate
- func Paths(paths ...string) Predicate
- func Prefixes(prefixes ...string) Predicate
- func Preflight() Predicate
- func QueryContains(name, value string) Predicate
- func QueryEquals(name, value string) Predicate
- func QueryExists(name string) Predicate
- func SafeMethods() Predicate
- func Static() Predicate
- func Suffixes(suffixes ...string) Predicate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(middleware fh.HandlerFunc, predicate Predicate) fh.HandlerFunc
New wraps middleware and skips it when predicate returns true.
func NewWithConfig ¶
func NewWithConfig(middleware fh.HandlerFunc, cfg Config) fh.HandlerFunc
NewWithConfig wraps middleware using a full skip configuration.
Types ¶
type Config ¶
type Config struct {
// Predicate is the main predicate. If it returns true, middleware is skipped.
Predicate Predicate
// Predicates are additional predicates combined using Logic.
Predicates []Predicate
// Logic controls how Predicate + Predicates are combined.
// Default is LogicAny.
Logic Logic
// RecoverPredicatePanic controls whether predicate panics are recovered.
// Default true. A panicking predicate is treated as "do not skip".
RecoverPredicatePanic bool
// OnPredicatePanic is called after a predicate panic is recovered.
OnPredicatePanic func(fh.Ctx, any)
}
Config configures skip behavior.
type Predicate ¶
Predicate returns true when the wrapped middleware should be skipped.
func Globs ¶
Globs skips middleware when request path matches one of the glob patterns.
Uses path.Match syntax:
/static/* /assets/*.css /api/v?/health
func HeaderContains ¶
HeaderContains skips middleware when a request header contains value.
func HeaderEquals ¶
HeaderEquals skips middleware when a request header exactly matches value.
func HeaderExists ¶
HeaderExists skips middleware when a request header exists.
func HeaderPrefix ¶
HeaderPrefix skips middleware when a request header has prefix.
func HeaderSuffix ¶
HeaderSuffix skips middleware when a request header has suffix.
func Methods ¶
Methods skips middleware for exact HTTP methods. Method matching is case-insensitive.
func QueryContains ¶
QueryContains skips middleware when a query parameter contains value.
func QueryEquals ¶
QueryEquals skips middleware when a query parameter exactly matches value.
func QueryExists ¶
QueryExists skips middleware when a query parameter exists.