You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,10 @@ their respective handler.
17
17
18
18
The name mux stands for "HTTP request multiplexer". Like the standard `http.ServeMux`, `mux.Router` matches incoming requests against a list of registered routes and calls a handler for the route that matches the URL or other conditions. The main features are:
19
19
20
-
* It implements the `http.Handler` interface so it is compatible with the standard `http.ServeMux`.
20
+
* It implements the `http.Handler` interface so, it is compatible with the standard `http.ServeMux`.
21
21
* Requests can be matched based on URL host, path, path prefix, schemes, header and query values, HTTP methods or using custom matchers.
22
22
* URL hosts, paths and query values can have variables with an optional regular expression.
23
-
* Registered URLs can be built, or "reversed", which helps maintaining references to resources.
23
+
* Registered URLs can be built, or "reversed", which helps to maintain references to resources.
24
24
* Routes can be used as subrouters: nested routes are only tested if the parent route matches. This is useful to define groups of routes that share common conditions like a host, a path prefix or other repeated attributes. As a bonus, this optimizes request matching.
25
25
26
26
---
@@ -307,7 +307,7 @@ func main() {
307
307
308
308
Now let's see how to build registered URLs.
309
309
310
-
Routes can be named. All routes that define a name can have their URLs built, or "reversed". We define a namecalling `Name()` on a route. For example:
310
+
Routes can be named. All routes that define a name can have their URLs built, or "reversed". We define a name-calling `Name()` on a route. For example:
The `Walk` function on `mux.Router` can be used to visit all of the routes that are registered on a router. For example,
385
-
the following prints all of the registered routes:
384
+
The `Walk` function on `mux.Router` can be used to visit all the routes that are registered on a router. For example,
385
+
the following prints all the registered routes:
386
386
387
387
```go
388
388
package main
@@ -515,7 +515,7 @@ Mux middlewares are defined using the de facto standard type:
515
515
typeMiddlewareFuncfunc(http.Handler) http.Handler
516
516
```
517
517
518
-
Typically, the returned handler is a closure which does something with the http.ResponseWriter and http.Request passed to it, and then calls the handler passed as parameter to the MiddlewareFunc. This takes advantage of closures being able access variables from the context where they are created, while retaining the signature enforced by the receivers.
518
+
Typically, the returned handler is a closure which does something with the http.ResponseWriter and http.Request passed to it, and then calls the handler passed as parameter to the MiddlewareFunc. This takes advantage of closures being able to access variables from the context where they are created, while retaining the signature enforced by the receivers.
519
519
520
520
A very basic middleware which logs the URI of the request being handled could be written as:
521
521
@@ -623,7 +623,7 @@ func fooHandler(w http.ResponseWriter, r *http.Request) {
...and the route will match both requests with a Content-Type of `application/json` as well as
215
+
...and the route will match both requests with a Content-Type of `application/json` and
216
216
`application/text`
217
217
218
218
There's also a way to build only the URL host or path for a route:
@@ -301,6 +301,5 @@ A more complex authentication middleware, which maps session token to users, cou
301
301
r.Use(amw.Middleware)
302
302
303
303
Note: The handler chain will be stopped if your middleware doesn't call `next.ServeHTTP()` with the corresponding parameters. This can be used to abort a request if the middleware writer wants to.
0 commit comments