pattern

package
v1.0.0-beta.1 Latest Latest
Warning

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

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

Documentation

Overview

Package pattern joins and checks route paths written in Go's net/http pattern syntax ("/users/{id}", "/files/{path...}").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Join

func Join(parts ...string) string

Join concatenates path parts with exactly one slash between them. Empty parts and "/" parts are skipped. A trailing slash on the last non-empty part is kept, and becomes "{$}" so that ServeMux matches it exactly instead of as a subtree. The root path "/" becomes "/{$}" for the same reason; use "/{path...}" for a catch-all.

func Normalize

func Normalize(path string) string

Normalize replaces wildcard names so that two patterns matching the same requests compare equal: "/users/{id}" and "/users/{name}" both become "/users/{}".

func Validate

func Validate(path string) error

Validate reports problems with a joined path: :name style segments, bad wildcard names, a "..." wildcard that is not last, and duplicate wildcard names.

func Wildcards

func Wildcards(path string) []string

Wildcards returns the wildcard names in path, in order.

Types

This section is empty.

Jump to

Keyboard shortcuts

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