matcher

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package matcher provides route-level middleware selection: it maps a transport operation to the middlewares that apply to it, so different endpoints can carry different cross-cutting concerns (e.g. rate limiting only under /admin/*). It is inspired by kratos' internal matcher and is transport-agnostic.

An operation is the gRPC full method, or for HTTP the verb and the *route template* ("GET /v1/users/:userID") rather than the request path — so a selector written here keeps matching the route no matter which id is in the request. See transport.Transporter.Operation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(m *Matcher) middleware.Middleware

Match returns a unified Middleware that, per request, selects the middlewares applying to the current transport operation (gRPC full method or "METHOD /route/template") and chains them around next. It composes with the existing middleware.UnaryServerInterceptor and middleware.GinHandler bridges, so a single matcher serves both protocols.

Types

type Matcher

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

Matcher selects middlewares by operation. Use registers global defaults; Add registers middlewares for a selector. Selectors are either an exact operation ("/pkg.Service/Method"), a prefix ending in "*" ("/pkg.Service/*"), or "*" for every operation.

func New

func New() *Matcher

New returns an empty Matcher.

func (*Matcher) Add

func (m *Matcher) Add(selector string, mws ...middleware.Middleware) *Matcher

Add registers middlewares for a selector, returning m for chaining.

func (*Matcher) Match

func (m *Matcher) Match(operation string) []middleware.Middleware

Match returns the middlewares applying to operation: defaults first, then an exact match, then prefix matches from longest to shortest prefix.

func (*Matcher) Use

func (m *Matcher) Use(mws ...middleware.Middleware) *Matcher

Use appends global middlewares applied to every operation, outermost first.

Jump to

Keyboard shortcuts

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