Skip to content

Commit 63c5c2f

Browse files
elithrarkisielk
authored andcommitted
[docs] Fix Middleware docs typos (#332)
1 parent 85e6bff commit 63c5c2f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ Typically, the returned handler is a closure which does something with the http.
465465
A very basic middleware which logs the URI of the request being handled could be written as:
466466

467467
```go
468-
func simpleMw(next http.Handler) http.Handler {
468+
func loggingMiddleware(next http.Handler) http.Handler {
469469
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
470470
// Do stuff here
471471
log.Println(r.RequestURI)
@@ -475,12 +475,12 @@ func simpleMw(next http.Handler) http.Handler {
475475
}
476476
```
477477

478-
Middlewares can be added to a router using `Router.AddMiddlewareFunc()`:
478+
Middlewares can be added to a router using `Router.Use()`:
479479

480480
```go
481481
r := mux.NewRouter()
482482
r.HandleFunc("/", handler)
483-
r.AddMiddleware(simpleMw)
483+
r.Use(loggingMiddleware)
484484
```
485485

486486
A more complex authentication middleware, which maps session token to users, could be written as:
@@ -524,7 +524,7 @@ r.HandleFunc("/", handler)
524524
amw := authenticationMiddleware{}
525525
amw.Populate()
526526

527-
r.AddMiddlewareFunc(amw.Middleware)
527+
r.Use(amw.Middleware)
528528
```
529529

530530
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. Middlewares *should* write to `ResponseWriter` if they *are* going to terminate the request, and they *should not* write to `ResponseWriter` if they *are not* going to terminate it.

0 commit comments

Comments
 (0)