route

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package route matches HTTP requests against net/http.ServeMux patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wildcards

func Wildcards(pattern string) []string

Wildcards returns the names of a valid pattern's path wildcards in order.

Types

type Map

type Map[T any] struct {
	// contains filtered or unexported fields
}

Map assigns a value to each pattern. Build it with Add before sharing it; concurrent Match calls are safe once construction is complete.

func New

func New[T any]() *Map[T]

New returns an empty map.

func (*Map[T]) Add

func (m *Map[T]) Add(pattern string, value T) error

Add assigns a value to a "<METHOD> [<host>]/<path>" pattern, which must name an HTTP method. A pattern without a host matches every host.

func (*Map[T]) Match

func (m *Map[T]) Match(requestMethod, requestHost, requestPath string) (value T, wildcards map[string]string, matched bool)

Match returns a request's value and wildcards; requestPath must be escaped. Unlike ServeMux, a GET pattern does not match HEAD, whose empty responses need their own pattern.

type Matcher

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

Matcher holds the HTTP endpoints and rules that scripts declare. The engine declares every one before serving starts; matching is then safe for concurrent use.

func NewMatcher

func NewMatcher() *Matcher

NewMatcher returns a matcher with no endpoints.

func (*Matcher) Declare

func (m *Matcher) Declare(declaration protocol.Declaration) error

Declare adds an endpoint or a rule. Egress request patterns name a host; ingress rule patterns do not.

func (*Matcher) Request

func (m *Matcher) Request(requestMethod, requestHost, requestPath string) (request Request, wildcards map[string]string, matched bool)

Request returns the endpoint a dependency request matches and its path wildcards. requestPath must be escaped.

func (*Matcher) Requests

func (m *Matcher) Requests() []Request

Requests returns the declared egress endpoints in declaration order.

func (*Matcher) Responses added in v0.43.0

func (m *Matcher) Responses(requestMethod, requestPath string, header http.Header) (rules []javascript.Rule, ignored Option[string])

Responses returns, in order, the rules that may select an inbound request's responses, or why every response is ignored. requestPath must be escaped.

type Pattern added in v0.43.0

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

Pattern is one "[<METHOD> ][<host>]/<path>" pattern. Without a method it matches every method; otherwise, as in Map, a GET pattern does not match HEAD.

func NewPattern added in v0.43.0

func NewPattern(pattern string) (*Pattern, error)

NewPattern checks a pattern and returns a matcher for it.

func (*Pattern) Match added in v0.43.0

func (p *Pattern) Match(requestMethod, requestHost, requestPath string) (matched bool)

Match reports whether a request matches the pattern; requestPath must be escaped.

type Request

type Request struct {
	Pattern string
	Type    schema.TypeRef
}

Request is one declared egress endpoint.

Jump to

Keyboard shortcuts

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