Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-chi/chi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.0.1
Choose a base ref
...
head repository: go-chi/chi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.0.2
Choose a head ref
  • 6 commits
  • 6 files changed
  • 2 contributors

Commits on Mar 11, 2021

  1. Copy the full SHA
    1e23150 View commit details

Commits on Mar 25, 2021

  1. Copy the full SHA
    c1fd4eb View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a846def View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ab14a9a View commit details
  4. Copy the full SHA
    969d7fc View commit details
  5. v5.0.2

    pkieltyka committed Mar 25, 2021
    Copy the full SHA
    2283e49 View commit details
Showing with 41 additions and 13 deletions.
  1. +6 −1 CHANGELOG.md
  2. +9 −0 _examples/rest/go.mod
  3. +8 −0 _examples/rest/go.sum
  4. +2 −1 _examples/rest/main.go
  5. +5 −5 middleware/throttle_test.go
  6. +11 −6 mux.go
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## v5.0.1 (201-03-10)
## v5.0.2 (2021-03-25)

- History of changes: see https://github.com/go-chi/chi/compare/v5.0.1...v5.0.2


## v5.0.1 (2021-03-10)

- Small improvements
- History of changes: see https://github.com/go-chi/chi/compare/v5.0.0...v5.0.1
9 changes: 9 additions & 0 deletions _examples/rest/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module rest-example

go 1.16

require (
github.com/go-chi/chi/v5 v5.0.1
github.com/go-chi/docgen v1.2.0
github.com/go-chi/render v1.0.1
)
8 changes: 8 additions & 0 deletions _examples/rest/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/go-chi/chi/v5 v5.0.1 h1:ALxjCrTf1aflOlkhMnCUP86MubbWFrzB3gkRPReLpTo=
github.com/go-chi/chi/v5 v5.0.1/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/docgen v1.2.0 h1:da0Nq2PKU9W9pSOTUfVrKI1vIgTGpauo9cfh4Iwivek=
github.com/go-chi/docgen v1.2.0/go.mod h1:G9W0G551cs2BFMSn/cnGwX+JBHEloAgo17MBhyrnhPI=
github.com/go-chi/render v1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8=
github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
3 changes: 2 additions & 1 deletion _examples/rest/main.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@
// This example demonstrates a HTTP REST web service with some fixture data.
// Follow along the example and patterns.
//
// Also check routes.json for the generated docs from passing the -routes flag
// Also check routes.json for the generated docs from passing the -routes flag,
// to run yourself do: `go run . -routes`
//
// Boot the server:
// ----------------
10 changes: 5 additions & 5 deletions middleware/throttle_test.go
Original file line number Diff line number Diff line change
@@ -146,11 +146,11 @@ func TestThrottleTriggerGatewayTimeout(t *testing.T) {
func TestThrottleMaximum(t *testing.T) {
r := chi.NewRouter()

r.Use(ThrottleBacklog(50, 50, time.Second*5))
r.Use(ThrottleBacklog(10, 10, time.Second*5))

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
time.Sleep(time.Second * 2) // Expensive operation.
time.Sleep(time.Second * 3) // Expensive operation.
w.Write(testContent)
})

@@ -163,7 +163,7 @@ func TestThrottleMaximum(t *testing.T) {

var wg sync.WaitGroup

for i := 0; i < 100; i++ {
for i := 0; i < 20; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
@@ -180,11 +180,11 @@ func TestThrottleMaximum(t *testing.T) {
}

// Wait less time than what the server takes to reply.
time.Sleep(time.Second * 1)
time.Sleep(time.Second * 2)

// At this point the server is still processing, all the following request
// will be beyond the server capacity.
for i := 0; i < 100; i++ {
for i := 0; i < 20; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
17 changes: 11 additions & 6 deletions mux.go
Original file line number Diff line number Diff line change
@@ -189,16 +189,17 @@ func (mx *Mux) Trace(pattern string, handlerFn http.HandlerFunc) {
func (mx *Mux) NotFound(handlerFn http.HandlerFunc) {
// Build NotFound handler chain
m := mx
h := Chain(mx.middlewares...).HandlerFunc(handlerFn).ServeHTTP
hFn := handlerFn
if mx.inline && mx.parent != nil {
m = mx.parent
hFn = Chain(mx.middlewares...).HandlerFunc(hFn).ServeHTTP
}

// Update the notFoundHandler from this point forward
m.notFoundHandler = h
m.notFoundHandler = hFn
m.updateSubRoutes(func(subMux *Mux) {
if subMux.notFoundHandler == nil {
subMux.NotFound(h)
subMux.NotFound(hFn)
}
})
}
@@ -208,16 +209,17 @@ func (mx *Mux) NotFound(handlerFn http.HandlerFunc) {
func (mx *Mux) MethodNotAllowed(handlerFn http.HandlerFunc) {
// Build MethodNotAllowed handler chain
m := mx
h := Chain(mx.middlewares...).HandlerFunc(handlerFn).ServeHTTP
hFn := handlerFn
if mx.inline && mx.parent != nil {
m = mx.parent
hFn = Chain(mx.middlewares...).HandlerFunc(hFn).ServeHTTP
}

// Update the methodNotAllowedHandler from this point forward
m.methodNotAllowedHandler = h
m.methodNotAllowedHandler = hFn
m.updateSubRoutes(func(subMux *Mux) {
if subMux.methodNotAllowedHandler == nil {
subMux.MethodNotAllowed(h)
subMux.MethodNotAllowed(hFn)
}
})
}
@@ -420,6 +422,9 @@ func (mx *Mux) routeHTTP(w http.ResponseWriter, r *http.Request) {
} else {
routePath = r.URL.Path
}
if routePath == "" {
routePath = "/"
}
}

// Check if method is supported by chi