diff options
Diffstat (limited to 'src/net/http/example_test.go')
-rw-r--r-- | src/net/http/example_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/net/http/example_test.go b/src/net/http/example_test.go index f5c47d0bd4..2a09f5f6c6 100644 --- a/src/net/http/example_test.go +++ b/src/net/http/example_test.go @@ -173,3 +173,21 @@ func ExampleHandleFunc() { log.Fatal(http.ListenAndServe(":8080", nil)) } + +func newPeopleHandler() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "This is the people handler.") + }) +} + +func ExampleNotFoundHandler() { + mux := http.NewServeMux() + + // Create sample handler to returns 404 + mux.Handle("/resources", http.NotFoundHandler()) + + // Create sample handler that returns 200 + mux.Handle("/resources/people/", newPeopleHandler()) + + log.Fatal(http.ListenAndServe(":8080", mux)) +} |