Documentation
¶
Overview ¶
Package route matches HTTP requests against net/http.ServeMux patterns.
Index ¶
- func Wildcards(pattern string) []string
- type Map
- type Matcher
- func (m *Matcher) Declare(pattern string, declaration protocol.Declaration) error
- func (m *Matcher) Request(requestMethod, requestHost, requestPath string) (request Request, wildcards map[string]string, matched bool)
- func (m *Matcher) Requests() []Request
- func (m *Matcher) Response(requestMethod, requestPath string) (ref schema.TypeRef, ignored Option[string], matched bool)
- type Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*Map[T]) Add ¶
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 (*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.