route

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 5 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 added in v0.14.0

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.

Jump to

Keyboard shortcuts

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