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
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
504
506
token:= r.Header.Get("X-Session-Token")
505
-
507
+
506
508
ifuser, found:= amw.tokenUsers[token]; found {
507
509
// We found the token in our map
508
510
log.Printf("Authenticated user %s\n", user)
@@ -526,7 +528,130 @@ amw.Populate()
526
528
r.AddMiddlewareFunc(amw.Middleware)
527
529
```
528
530
529
-
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.
531
+
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.
532
+
533
+
### Testing Handlers
534
+
535
+
Testing handlers in a Go web application is straightforward, and _mux_ doesn't complicate this any further. Given two files: `endpoints.go` and `endpoints_test.go`, here's how we'd test an application using _mux_.
536
+
537
+
First, our simple HTTP handler:
538
+
539
+
```go
540
+
// endpoints.go
541
+
package main
542
+
543
+
funcHealthCheckHandler(whttp.ResponseWriter, r *http.Request) {
0 commit comments