route

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 8 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 that scripts declare. The engine declares every endpoint 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(pattern string, declaration protocol.Declaration) error

Declare adds an endpoint. Egress request patterns name a host; ingress 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) Response

func (m *Matcher) Response(requestMethod, requestPath string) (ref schema.TypeRef, ignored Option[string], matched bool)

Response returns the response type for an inbound request, or why its responses are ignored. 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