Skip to content

Commit

Permalink
docs: update WrapH & WrapM examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerwill90 committed Jun 15, 2023
1 parent 4d29082 commit 7370b63
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,17 @@ func handle(c fox.Context) {
Fox itself implements the `http.Handler` interface which make easy to chain any compatible middleware before the router. Moreover, the router
provides convenient `fox.WrapF`, `fox.WrapH` and `fox.WrapM` adapter to be use with `http.Handler`.

The route parameters are being accessed by the wrapped handler through the `fox.Context` when the adapter `fox.WrapF` and `fox.WrapH` are used.
The route parameters are being accessed by the wrapped handler through the `context.Context` when the adapter `fox.WrapF` and `fox.WrapH` are used.

Wrapping an `http.Handler`
```go
articles := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintln(w, "get articles")
params := fox.ParamsFromContext(r.Context())
_, _ = fmt.Fprintf(w, "Article id: %s\n", params.Get("id"))
})

f := fox.New(fox.DefaultOptions())
f.MustHandle(http.MethodGet, "/articles", fox.WrapH(httpRateLimiter.RateLimit(articles)))
f.MustHandle(http.MethodGet, "/articles/{id}", fox.WrapH(httpRateLimiter.RateLimit(articles)))
```

Wrapping an `http.Handler` compatible middleware
Expand Down

0 comments on commit 7370b63

Please sign in to comment.