diff options
Diffstat (limited to 'vendor/github.com/go-chi')
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/README.md | 6 | ||||
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/chi.go | 3 | ||||
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/context.go | 9 | ||||
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/mux.go | 17 | ||||
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/path_value.go | 5 | ||||
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/path_value_fallback.go | 4 | ||||
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/pattern.go | 16 | ||||
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/pattern_fallback.go | 17 | ||||
| -rw-r--r-- | vendor/github.com/go-chi/chi/v5/tree.go | 21 |
9 files changed, 59 insertions, 39 deletions
diff --git a/vendor/github.com/go-chi/chi/v5/README.md b/vendor/github.com/go-chi/chi/v5/README.md index 7f662ab..c58a0e2 100644 --- a/vendor/github.com/go-chi/chi/v5/README.md +++ b/vendor/github.com/go-chi/chi/v5/README.md @@ -20,7 +20,9 @@ and [docgen](https://github.com/go-chi/docgen). We hope you enjoy it too! ## Install -`go get -u github.com/go-chi/chi/v5` +```sh +go get -u github.com/go-chi/chi/v5 +``` ## Features @@ -194,7 +196,7 @@ type Router interface { // path, with a fresh middleware stack for the inline-Router. Group(fn func(r Router)) Router - // Route mounts a sub-Router along a `pattern`` string. + // Route mounts a sub-Router along a `pattern` string. Route(pattern string, fn func(r Router)) Router // Mount attaches another http.Handler along ./pattern/* diff --git a/vendor/github.com/go-chi/chi/v5/chi.go b/vendor/github.com/go-chi/chi/v5/chi.go index fc32c4e..2b6ebd3 100644 --- a/vendor/github.com/go-chi/chi/v5/chi.go +++ b/vendor/github.com/go-chi/chi/v5/chi.go @@ -37,8 +37,7 @@ // // A placeholder with a name followed by a colon allows a regular // expression match, for example {number:\\d+}. The regular expression -// syntax is Go's normal regexp RE2 syntax, except that regular expressions -// including { or } are not supported, and / will never be +// syntax is Go's normal regexp RE2 syntax, except that / will never be // matched. An anonymous regexp pattern is allowed, using an empty string // before the colon in the placeholder, such as {:\\d+} // diff --git a/vendor/github.com/go-chi/chi/v5/context.go b/vendor/github.com/go-chi/chi/v5/context.go index aacf6ef..8222073 100644 --- a/vendor/github.com/go-chi/chi/v5/context.go +++ b/vendor/github.com/go-chi/chi/v5/context.go @@ -133,11 +133,12 @@ func (x *Context) RoutePattern() string { return routePattern } -// replaceWildcards takes a route pattern and recursively replaces all -// occurrences of "/*/" to "/". +// replaceWildcards takes a route pattern and replaces all occurrences of +// "/*/" with "/". It iteratively runs until no wildcards remain to +// correctly handle consecutive wildcards. func replaceWildcards(p string) string { - if strings.Contains(p, "/*/") { - return replaceWildcards(strings.Replace(p, "/*/", "/", -1)) + for strings.Contains(p, "/*/") { + p = strings.ReplaceAll(p, "/*/", "/") } return p } diff --git a/vendor/github.com/go-chi/chi/v5/mux.go b/vendor/github.com/go-chi/chi/v5/mux.go index 91daf69..ad66bba 100644 --- a/vendor/github.com/go-chi/chi/v5/mux.go +++ b/vendor/github.com/go-chi/chi/v5/mux.go @@ -107,9 +107,9 @@ func (mx *Mux) Use(middlewares ...func(http.Handler) http.Handler) { // Handle adds the route `pattern` that matches any http method to // execute the `handler` http.Handler. func (mx *Mux) Handle(pattern string, handler http.Handler) { - parts := strings.SplitN(pattern, " ", 2) - if len(parts) == 2 { - mx.Method(parts[0], parts[1], handler) + if i := strings.IndexAny(pattern, " \t"); i >= 0 { + method, rest := pattern[:i], strings.TrimLeft(pattern[i+1:], " \t") + mx.Method(method, rest, handler) return } @@ -119,13 +119,7 @@ func (mx *Mux) Handle(pattern string, handler http.Handler) { // HandleFunc adds the route `pattern` that matches any http method to // execute the `handlerFn` http.HandlerFunc. func (mx *Mux) HandleFunc(pattern string, handlerFn http.HandlerFunc) { - parts := strings.SplitN(pattern, " ", 2) - if len(parts) == 2 { - mx.Method(parts[0], parts[1], handlerFn) - return - } - - mx.handle(mALL, pattern, handlerFn) + mx.Handle(pattern, handlerFn) } // Method adds the route `pattern` that matches `method` http method to @@ -476,6 +470,9 @@ func (mx *Mux) routeHTTP(w http.ResponseWriter, r *http.Request) { if supportsPathValue { setPathValue(rctx, r) } + if supportsPattern { + setPattern(rctx, r) + } h.ServeHTTP(w, r) return diff --git a/vendor/github.com/go-chi/chi/v5/path_value.go b/vendor/github.com/go-chi/chi/v5/path_value.go index 7e78171..77c840f 100644 --- a/vendor/github.com/go-chi/chi/v5/path_value.go +++ b/vendor/github.com/go-chi/chi/v5/path_value.go @@ -1,5 +1,6 @@ -//go:build go1.22 -// +build go1.22 +//go:build go1.22 && !tinygo +// +build go1.22,!tinygo + package chi diff --git a/vendor/github.com/go-chi/chi/v5/path_value_fallback.go b/vendor/github.com/go-chi/chi/v5/path_value_fallback.go index f551781..749a852 100644 --- a/vendor/github.com/go-chi/chi/v5/path_value_fallback.go +++ b/vendor/github.com/go-chi/chi/v5/path_value_fallback.go @@ -1,5 +1,5 @@ -//go:build !go1.22 -// +build !go1.22 +//go:build !go1.22 || tinygo +// +build !go1.22 tinygo package chi diff --git a/vendor/github.com/go-chi/chi/v5/pattern.go b/vendor/github.com/go-chi/chi/v5/pattern.go new file mode 100644 index 0000000..890a2c2 --- /dev/null +++ b/vendor/github.com/go-chi/chi/v5/pattern.go @@ -0,0 +1,16 @@ +//go:build go1.23 && !tinygo +// +build go1.23,!tinygo + +package chi + +import "net/http" + +// supportsPattern is true if the Go version is 1.23 and above. +// +// If this is true, `net/http.Request` has field `Pattern`. +const supportsPattern = true + +// setPattern sets the mux matched pattern in the http Request. +func setPattern(rctx *Context, r *http.Request) { + r.Pattern = rctx.routePattern +} diff --git a/vendor/github.com/go-chi/chi/v5/pattern_fallback.go b/vendor/github.com/go-chi/chi/v5/pattern_fallback.go new file mode 100644 index 0000000..48a94ef --- /dev/null +++ b/vendor/github.com/go-chi/chi/v5/pattern_fallback.go @@ -0,0 +1,17 @@ +//go:build !go1.23 || tinygo +// +build !go1.23 tinygo + +package chi + +import "net/http" + +// supportsPattern is true if the Go version is 1.23 and above. +// +// If this is true, `net/http.Request` has field `Pattern`. +const supportsPattern = false + +// setPattern sets the mux matched pattern in the http Request. +// +// setPattern is only supported in Go 1.23 and above so +// this is just a blank function so that it compiles. +func setPattern(rctx *Context, r *http.Request) {} diff --git a/vendor/github.com/go-chi/chi/v5/tree.go b/vendor/github.com/go-chi/chi/v5/tree.go index c7d3bc5..bcb86b6 100644 --- a/vendor/github.com/go-chi/chi/v5/tree.go +++ b/vendor/github.com/go-chi/chi/v5/tree.go @@ -650,11 +650,9 @@ func (n *node) routes() []Route { if h.handler == nil { continue } - m := methodTypString(mt) - if m == "" { - continue + if m, ok := reverseMethodMap[mt]; ok { + hs[m] = h.handler } - hs[m] = h.handler } rt := Route{subroutes, hs, p} @@ -730,11 +728,9 @@ func patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) { tail = pattern[pe] } - var rexpat string - if idx := strings.Index(key, ":"); idx >= 0 { + key, rexpat, isRegexp := strings.Cut(key, ":") + if isRegexp { nt = ntRegexp - rexpat = key[idx+1:] - key = key[:idx] } if len(rexpat) > 0 { @@ -790,15 +786,6 @@ func longestPrefix(k1, k2 string) int { return i } -func methodTypString(method methodTyp) string { - for s, t := range methodMap { - if method == t { - return s - } - } - return "" -} - type nodes []*node // Sort the list of nodes by label |
