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 ¶
- func DescribeRelationship(pat1, pat2 string) string
- func PathValue(r *http.Request, name string) string
- type Pattern
- type ServeMux
- func (mux *ServeMux) Handle(pattern string, handler http.Handler)
- func (mux *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (mux *ServeMux) Handler(r *http.Request) (h http.Handler, pattern string)
- func (mux *ServeMux) PathValue(r *http.Request, name string) string
- func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (mux *ServeMux) SetPathValue(r *http.Request, name, value string)
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.
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 whose method and path is more specific win. One pattern is more specific than another if the second matches all the (method, path) pairs of the first and more.
type ServeMux ¶ added in v0.2.0
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is an HTTP request multiplexer. It behaves like net/http.ServeMux, but using the enhanced patterns of this package.
func NewServeMux ¶ added in v0.2.0
func NewServeMux() *ServeMux
func (*ServeMux) HandleFunc ¶ added in v0.2.0
func (*ServeMux) PathValue ¶ added in v0.2.0
PathValue calls the top-level PathValue function. deprecated: use PathValue.