diff --git a/assets/catnip/go.mod b/assets/catnip/go.mod index 9f715b95e..06e6102ff 100644 --- a/assets/catnip/go.mod +++ b/assets/catnip/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( code.cloudfoundry.org/clock v1.1.0 - github.com/go-chi/chi/v5 v5.0.10 + github.com/go-chi/chi/v5 v5.0.11 github.com/onsi/ginkgo/v2 v2.13.2 github.com/onsi/gomega v1.30.0 ) diff --git a/assets/catnip/go.sum b/assets/catnip/go.sum index d530f20ba..edfa743a5 100644 --- a/assets/catnip/go.sum +++ b/assets/catnip/go.sum @@ -6,8 +6,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= -github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= +github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/CHANGELOG.md b/assets/catnip/vendor/github.com/go-chi/chi/v5/CHANGELOG.md index f6eb7e6e4..83d5aa28f 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/CHANGELOG.md +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/CHANGELOG.md @@ -1,9 +1,14 @@ # Changelog +## v5.0.11 (2023-12-19) + +- History of changes: see https://github.com/go-chi/chi/compare/v5.0.10...v5.0.11 + + ## v5.0.10 (2023-07-13) - Fixed small edge case in tests of v5.0.9 for older Go versions -- History of changes: see https://github.com/go-chi/chi/compare/v5.0.8...v5.0.10 +- History of changes: see https://github.com/go-chi/chi/compare/v5.0.9...v5.0.10 ## v5.0.9 (2023-07-13) @@ -306,7 +311,7 @@ Cheers all, happy coding! request-scoped values. We're very excited about the new context addition and are proud to introduce chi v2, a minimal and powerful routing package for building large HTTP services, with zero external dependencies. Chi focuses on idiomatic design and encourages the use of - stdlib HTTP handlers and middlwares. + stdlib HTTP handlers and middlewares. - chi v2 deprecates its `chi.Handler` interface and requires `http.Handler` or `http.HandlerFunc` - chi v2 stores URL routing parameters and patterns in the standard request context: `r.Context()` - chi v2 lower-level routing context is accessible by `chi.RouteContext(r.Context()) *chi.Context`, diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/README.md b/assets/catnip/vendor/github.com/go-chi/chi/v5/README.md index 718e373fa..4b1c99d12 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/README.md +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/README.md @@ -494,7 +494,7 @@ Copyright (c) 2015-present [Peter Kieltyka](https://github.com/pkieltyka) Licensed under [MIT License](./LICENSE) -[GoDoc]: https://pkg.go.dev/github.com/go-chi/chi?tab=versions +[GoDoc]: https://pkg.go.dev/github.com/go-chi/chi/v5 [GoDoc Widget]: https://godoc.org/github.com/go-chi/chi?status.svg [Travis]: https://travis-ci.org/go-chi/chi [Travis Widget]: https://travis-ci.org/go-chi/chi.svg?branch=master diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/SECURITY.md b/assets/catnip/vendor/github.com/go-chi/chi/v5/SECURITY.md new file mode 100644 index 000000000..7e937f87f --- /dev/null +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/SECURITY.md @@ -0,0 +1,5 @@ +# Reporting Security Issues + +We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. + +To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/go-chi/chi/security/advisories/new) tab. diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/context.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/context.go index 88f8e221a..82e5f2890 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/context.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/context.go @@ -60,7 +60,7 @@ type Context struct { URLParams RouteParams // Route parameters matched for the current sub-router. It is - // intentionally unexported so it cant be tampered. + // intentionally unexported so it can't be tampered. routeParams RouteParams // The endpoint routing pattern that matched the request URI path @@ -92,6 +92,7 @@ func (x *Context) Reset() { x.routeParams.Keys = x.routeParams.Keys[:0] x.routeParams.Values = x.routeParams.Values[:0] x.methodNotAllowed = false + x.methodsAllowed = x.methodsAllowed[:0] x.parentCtx = nil } @@ -113,18 +114,20 @@ func (x *Context) URLParam(key string) string { // // For example, // -// func Instrument(next http.Handler) http.Handler { -// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -// next.ServeHTTP(w, r) -// routePattern := chi.RouteContext(r.Context()).RoutePattern() -// measure(w, r, routePattern) -// }) -// } +// func Instrument(next http.Handler) http.Handler { +// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { +// next.ServeHTTP(w, r) +// routePattern := chi.RouteContext(r.Context()).RoutePattern() +// measure(w, r, routePattern) +// }) +// } func (x *Context) RoutePattern() string { routePattern := strings.Join(x.RoutePatterns, "") routePattern = replaceWildcards(routePattern) - routePattern = strings.TrimSuffix(routePattern, "//") - routePattern = strings.TrimSuffix(routePattern, "/") + if routePattern != "/" { + routePattern = strings.TrimSuffix(routePattern, "//") + routePattern = strings.TrimSuffix(routePattern, "/") + } return routePattern } diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/compress.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/compress.go index 773d47a16..28240c4b3 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/compress.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/compress.go @@ -137,14 +137,14 @@ func NewCompressor(level int, types ...string) *Compressor { // // For example, add the Brotli algorithm: // -// import brotli_enc "gopkg.in/kothar/brotli-go.v0/enc" +// import brotli_enc "gopkg.in/kothar/brotli-go.v0/enc" // -// compressor := middleware.NewCompressor(5, "text/html") -// compressor.SetEncoder("br", func(w io.Writer, level int) io.Writer { -// params := brotli_enc.NewBrotliParams() -// params.SetQuality(level) -// return brotli_enc.NewBrotliWriter(params, w) -// }) +// compressor := middleware.NewCompressor(5, "text/html") +// compressor.SetEncoder("br", func(w io.Writer, level int) io.Writer { +// params := brotli_enc.NewBrotliParams() +// params.SetQuality(level) +// return brotli_enc.NewBrotliWriter(params, w) +// }) func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { encoding = strings.ToLower(encoding) if encoding == "" { @@ -156,12 +156,8 @@ func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { // If we are adding a new encoder that is already registered, we have to // clear that one out first. - if _, ok := c.pooledEncoders[encoding]; ok { - delete(c.pooledEncoders, encoding) - } - if _, ok := c.encoders[encoding]; ok { - delete(c.encoders, encoding) - } + delete(c.pooledEncoders, encoding) + delete(c.encoders, encoding) // If the encoder supports Resetting (IoReseterWriter), then it can be pooled. encoder := fn(ioutil.Discard, c.level) @@ -201,7 +197,7 @@ func (c *Compressor) Handler(next http.Handler) http.Handler { contentTypes: c.allowedTypes, contentWildcards: c.allowedWildcards, encoding: encoding, - compressable: false, // determined in post-handler + compressible: false, // determined in post-handler } if encoder != nil { cw.w = encoder @@ -275,10 +271,10 @@ type compressResponseWriter struct { contentWildcards map[string]struct{} encoding string wroteHeader bool - compressable bool + compressible bool } -func (cw *compressResponseWriter) isCompressable() bool { +func (cw *compressResponseWriter) isCompressible() bool { // Parse the first part of the Content-Type response header. contentType := cw.Header().Get("Content-Type") if idx := strings.Index(contentType, ";"); idx >= 0 { @@ -310,13 +306,13 @@ func (cw *compressResponseWriter) WriteHeader(code int) { return } - if !cw.isCompressable() { - cw.compressable = false + if !cw.isCompressible() { + cw.compressible = false return } if cw.encoding != "" { - cw.compressable = true + cw.compressible = true cw.Header().Set("Content-Encoding", cw.encoding) cw.Header().Add("Vary", "Accept-Encoding") @@ -334,11 +330,10 @@ func (cw *compressResponseWriter) Write(p []byte) (int, error) { } func (cw *compressResponseWriter) writer() io.Writer { - if cw.compressable { + if cw.compressible { return cw.w - } else { - return cw.ResponseWriter } + return cw.ResponseWriter } type compressFlusher interface { diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/logger.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/logger.go index 98250d823..cff9bd206 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/logger.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/logger.go @@ -31,10 +31,11 @@ var ( // // IMPORTANT NOTE: Logger should go before any other middleware that may change // the response, such as middleware.Recoverer. Example: -// r := chi.NewRouter() -// r.Use(middleware.Logger) // <--<< Logger should come before Recoverer -// r.Use(middleware.Recoverer) -// r.Get("/", handler) +// +// r := chi.NewRouter() +// r.Use(middleware.Logger) // <--<< Logger should come before Recoverer +// r.Use(middleware.Recoverer) +// r.Get("/", handler) func Logger(next http.Handler) http.Handler { return DefaultLogger(next) } diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/nocache.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/nocache.go index 7353448d6..9308d40d7 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/nocache.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/nocache.go @@ -32,10 +32,11 @@ var etagHeaders = []string{ // a router (or subrouter) from being cached by an upstream proxy and/or client. // // As per http://wiki.nginx.org/HttpProxyModule - NoCache sets: -// Expires: Thu, 01 Jan 1970 00:00:00 UTC -// Cache-Control: no-cache, private, max-age=0 -// X-Accel-Expires: 0 -// Pragma: no-cache (for HTTP/1.0 proxies/clients) +// +// Expires: Thu, 01 Jan 1970 00:00:00 UTC +// Cache-Control: no-cache, private, max-age=0 +// X-Accel-Expires: 0 +// Pragma: no-cache (for HTTP/1.0 proxies/clients) func NoCache(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/profiler.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/profiler.go index 3c36f878f..ebd81ee4f 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/profiler.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/profiler.go @@ -2,7 +2,6 @@ package middleware import ( "expvar" - "fmt" "net/http" "net/http/pprof" @@ -11,13 +10,13 @@ import ( // Profiler is a convenient subrouter used for mounting net/http/pprof. ie. // -// func MyService() http.Handler { -// r := chi.NewRouter() -// // ..middlewares -// r.Mount("/debug", middleware.Profiler()) -// // ..routes -// return r -// } +// func MyService() http.Handler { +// r := chi.NewRouter() +// // ..middlewares +// r.Mount("/debug", middleware.Profiler()) +// // ..routes +// return r +// } func Profiler() http.Handler { r := chi.NewRouter() r.Use(NoCache) @@ -34,7 +33,7 @@ func Profiler() http.Handler { r.HandleFunc("/pprof/profile", pprof.Profile) r.HandleFunc("/pprof/symbol", pprof.Symbol) r.HandleFunc("/pprof/trace", pprof.Trace) - r.HandleFunc("/vars", expVars) + r.Handle("/vars", expvar.Handler()) r.Handle("/pprof/goroutine", pprof.Handler("goroutine")) r.Handle("/pprof/threadcreate", pprof.Handler("threadcreate")) @@ -45,18 +44,3 @@ func Profiler() http.Handler { return r } - -// Replicated from expvar.go as not public. -func expVars(w http.ResponseWriter, r *http.Request) { - first := true - w.Header().Set("Content-Type", "application/json") - fmt.Fprintf(w, "{\n") - expvar.Do(func(kv expvar.KeyValue) { - if !first { - fmt.Fprintf(w, ",\n") - } - first = false - fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) - }) - fmt.Fprintf(w, "\n}\n") -} diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go index 612e155a7..81342dfa7 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go @@ -113,15 +113,14 @@ func (s prettyStack) decorateLine(line string, useColor bool, num int) (string, line = strings.TrimSpace(line) if strings.HasPrefix(line, "\t") || strings.Contains(line, ".go:") { return s.decorateSourceLine(line, useColor, num) - } else if strings.HasSuffix(line, ")") { + } + if strings.HasSuffix(line, ")") { return s.decorateFuncCallLine(line, useColor, num) - } else { - if strings.HasPrefix(line, "\t") { - return strings.Replace(line, "\t", " ", 1), nil - } else { - return fmt.Sprintf(" %s\n", line), nil - } } + if strings.HasPrefix(line, "\t") { + return strings.Replace(line, "\t", " ", 1), nil + } + return fmt.Sprintf(" %s\n", line), nil } func (s prettyStack) decorateFuncCallLine(line string, useColor bool, num int) (string, error) { diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go index ea914a1d3..997bed569 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go @@ -11,39 +11,34 @@ import ( // For example, lets say you'd like to setup multiple routers depending on the // request Host header, you could then do something as so: // -// r := chi.NewRouter() -// rSubdomain := chi.NewRouter() -// -// r.Use(middleware.RouteHeaders(). -// Route("Host", "example.com", middleware.New(r)). -// Route("Host", "*.example.com", middleware.New(rSubdomain)). -// Handler) -// -// r.Get("/", h) -// rSubdomain.Get("/", h2) -// +// r := chi.NewRouter() +// rSubdomain := chi.NewRouter() +// r.Use(middleware.RouteHeaders(). +// Route("Host", "example.com", middleware.New(r)). +// Route("Host", "*.example.com", middleware.New(rSubdomain)). +// Handler) +// r.Get("/", h) +// rSubdomain.Get("/", h2) // // Another example, imagine you want to setup multiple CORS handlers, where for // your origin servers you allow authorized requests, but for third-party public // requests, authorization is disabled. // -// r := chi.NewRouter() -// -// r.Use(middleware.RouteHeaders(). -// Route("Origin", "https://app.skyweaver.net", cors.Handler(cors.Options{ -// AllowedOrigins: []string{"https://api.skyweaver.net"}, -// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, -// AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, -// AllowCredentials: true, // <----------<<< allow credentials -// })). -// Route("Origin", "*", cors.Handler(cors.Options{ -// AllowedOrigins: []string{"*"}, -// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, -// AllowedHeaders: []string{"Accept", "Content-Type"}, -// AllowCredentials: false, // <----------<<< do not allow credentials -// })). -// Handler) -// +// r := chi.NewRouter() +// r.Use(middleware.RouteHeaders(). +// Route("Origin", "https://app.skyweaver.net", cors.Handler(cors.Options{ +// AllowedOrigins: []string{"https://api.skyweaver.net"}, +// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, +// AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, +// AllowCredentials: true, // <----------<<< allow credentials +// })). +// Route("Origin", "*", cors.Handler(cors.Options{ +// AllowedOrigins: []string{"*"}, +// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, +// AllowedHeaders: []string{"Accept", "Content-Type"}, +// AllowCredentials: false, // <----------<<< do not allow credentials +// })). +// Handler) func RouteHeaders() HeaderRouter { return HeaderRouter{} } @@ -150,11 +145,7 @@ func NewPattern(value string) Pattern { func (p Pattern) Match(v string) bool { if !p.wildcard { - if p.prefix == v { - return true - } else { - return false - } + return p.prefix == v } return len(v) >= len(p.prefix+p.suffix) && strings.HasPrefix(v, p.prefix) && strings.HasSuffix(v, p.suffix) } diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/sunset.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/sunset.go new file mode 100644 index 000000000..18815d585 --- /dev/null +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/sunset.go @@ -0,0 +1,25 @@ +package middleware + +import ( + "net/http" + "time" +) + +// Sunset set Deprecation/Sunset header to response +// This can be used to enable Sunset in a route or a route group +// For more: https://www.rfc-editor.org/rfc/rfc8594.html +func Sunset(sunsetAt time.Time, links ...string) func(http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !sunsetAt.IsZero() { + w.Header().Set("Sunset", sunsetAt.Format(http.TimeFormat)) + w.Header().Set("Deprecation", sunsetAt.Format(http.TimeFormat)) + + for _, link := range links { + w.Header().Add("Link", link) + } + } + next.ServeHTTP(w, r) + }) + } +} diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go new file mode 100644 index 000000000..83a8a8721 --- /dev/null +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go @@ -0,0 +1,27 @@ +package middleware + +import ( + "net/http" + + "github.com/go-chi/chi/v5" +) + +// SupressNotFound will quickly respond with a 404 if the route is not found +// and will not continue to the next middleware handler. +// +// This is handy to put at the top of your middleware stack to avoid unnecessary +// processing of requests that are not going to match any routes anyway. For +// example its super annoying to see a bunch of 404's in your logs from bots. +func SupressNotFound(router *chi.Mux) func(next http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + rctx := chi.RouteContext(r.Context()) + match := rctx.Routes.Match(rctx, r.Method, r.URL.Path) + if !match { + router.NotFoundHandler().ServeHTTP(w, r) + return + } + next.ServeHTTP(w, r) + }) + } +} diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/timeout.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/timeout.go index 8e373536c..add596d69 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/timeout.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/timeout.go @@ -15,21 +15,20 @@ import ( // // ie. a route/handler may look like: // -// r.Get("/long", func(w http.ResponseWriter, r *http.Request) { -// ctx := r.Context() -// processTime := time.Duration(rand.Intn(4)+1) * time.Second +// r.Get("/long", func(w http.ResponseWriter, r *http.Request) { +// ctx := r.Context() +// processTime := time.Duration(rand.Intn(4)+1) * time.Second // -// select { -// case <-ctx.Done(): -// return +// select { +// case <-ctx.Done(): +// return // -// case <-time.After(processTime): -// // The above channel simulates some hard work. -// } -// -// w.Write([]byte("done")) -// }) +// case <-time.After(processTime): +// // The above channel simulates some hard work. +// } // +// w.Write([]byte("done")) +// }) func Timeout(timeout time.Duration) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/url_format.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/url_format.go index 919eb0fea..d8a651e4e 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/url_format.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/middleware/url_format.go @@ -20,30 +20,29 @@ var ( // // Routers should not include a url parameter for the suffix when using this middleware. // -// Sample usage.. for url paths: `/articles/1`, `/articles/1.json` and `/articles/1.xml` +// Sample usage for url paths `/articles/1`, `/articles/1.json` and `/articles/1.xml`: // -// func routes() http.Handler { -// r := chi.NewRouter() -// r.Use(middleware.URLFormat) +// func routes() http.Handler { +// r := chi.NewRouter() +// r.Use(middleware.URLFormat) // -// r.Get("/articles/{id}", ListArticles) +// r.Get("/articles/{id}", ListArticles) // -// return r -// } +// return r +// } // -// func ListArticles(w http.ResponseWriter, r *http.Request) { -// urlFormat, _ := r.Context().Value(middleware.URLFormatCtxKey).(string) -// -// switch urlFormat { -// case "json": -// render.JSON(w, r, articles) -// case "xml:" -// render.XML(w, r, articles) -// default: -// render.JSON(w, r, articles) -// } -// } +// func ListArticles(w http.ResponseWriter, r *http.Request) { +// urlFormat, _ := r.Context().Value(middleware.URLFormatCtxKey).(string) // +// switch urlFormat { +// case "json": +// render.JSON(w, r, articles) +// case "xml:" +// render.XML(w, r, articles) +// default: +// render.JSON(w, r, articles) +// } +// } func URLFormat(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() diff --git a/assets/catnip/vendor/github.com/go-chi/chi/v5/mux.go b/assets/catnip/vendor/github.com/go-chi/chi/v5/mux.go index 977aa52dd..735ab2323 100644 --- a/assets/catnip/vendor/github.com/go-chi/chi/v5/mux.go +++ b/assets/catnip/vendor/github.com/go-chi/chi/v5/mux.go @@ -250,20 +250,19 @@ func (mx *Mux) With(middlewares ...func(http.Handler) http.Handler) Router { return im } -// Group creates a new inline-Mux with a fresh middleware stack. It's useful +// Group creates a new inline-Mux with a copy of middleware stack. It's useful // for a group of handlers along the same routing path that use an additional // set of middlewares. See _examples/. func (mx *Mux) Group(fn func(r Router)) Router { - im := mx.With().(*Mux) + im := mx.With() if fn != nil { fn(im) } return im } -// Route creates a new Mux with a fresh middleware stack and mounts it -// along the `pattern` as a subrouter. Effectively, this is a short-hand -// call to Mount. See _examples/. +// Route creates a new Mux and mounts it along the `pattern` as a subrouter. +// Effectively, this is a short-hand call to Mount. See _examples/. func (mx *Mux) Route(pattern string, fn func(r Router)) Router { if fn == nil { panic(fmt.Sprintf("chi: attempting to Route() a nil subrouter on '%s'", pattern)) diff --git a/assets/catnip/vendor/modules.txt b/assets/catnip/vendor/modules.txt index 36befd27c..14b25af1a 100644 --- a/assets/catnip/vendor/modules.txt +++ b/assets/catnip/vendor/modules.txt @@ -2,7 +2,7 @@ ## explicit; go 1.20 code.cloudfoundry.org/clock code.cloudfoundry.org/clock/fakeclock -# github.com/go-chi/chi/v5 v5.0.10 +# github.com/go-chi/chi/v5 v5.0.11 ## explicit; go 1.14 github.com/go-chi/chi/v5 github.com/go-chi/chi/v5/middleware