Documentation ¶
Overview ¶
Package muxpatterns is a sample implementation of enhanced http.ServeMux routing patterns. See https://github.com/golang/go/discussions/60227.
The API in this package is for experimentation only. It is likely that none of it will be in the proposal.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DescribeRelationship ¶ added in v0.1.2
DescribeRelationship returns a string that describes how pat1 and pat2 are related, in terms of the paths they match.
Types ¶
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
A Pattern is something that can be matched against an HTTP request.
func Parse ¶
Parse parses a string into a Pattern. The string's syntax is
[METHOD] [HOST]/[PATH]
where:
- METHOD is the uppercase name of an HTTP method
- HOST is a hostname
- PATH consists of slash-separated segments, where each segment is either a literal or a wildcard of the form "{name}", "{name...}", or "{$}".
METHOD, HOST and PATH are all optional; that is, the string can be "/". If METHOD is present, it must be followed by a single space. Wildcard names must be valid Go identifiers. The "{$}" and "{name...}" wildcard must occur at the end of PATH. PATH may end with a '/'. Wildcard names in a path must be distinct.
func (*Pattern) ConflictsWith ¶
ConflictsWith reports whether p1 conflicts with p2, that is, whether there is a request that both match but where neither is higher precedence than the other.
func (*Pattern) HigherPrecedence ¶
HigherPrecedence reports whether p1 has higher precedence than p2. If p1 and p2 both match a request, then p1 will be chosen.
Precedence is defined by these rules:
- Patterns with a host win over patterns without a host.
- Patterns with a method win over patterns without a method.
- Patterns whose path is more specific win. One path pattern is more specific than another if the second matches all the paths of the first and more.
type PatternSet ¶
type PatternSet struct {
// contains filtered or unexported fields
}
A PatternSet is a set of non-conflicting patterns. The zero value is an empty PatternSet, ready for use.
func (*PatternSet) Match ¶
func (s *PatternSet) Match(method, host, path string) (*Pattern, map[string]string)
Match matches the method, host and path against the patterns in the PatternSet. It returns the highest-precedence matching pattern and a map from wildcard names to matching path segments. Match returns (nil, nil, nil) if there is no matching pattern.
func (*PatternSet) MatchRequest ¶
MatchRequest calls Match with the request's method, host and path.
func (*PatternSet) Register ¶
func (s *PatternSet) Register(p *Pattern) error
Register adds a Pattern to the set. If returns an error if the pattern conflicts with an existing pattern in the set.