diff options
author | esell <eujon.sellers@gmail.com> | 2018-08-30 12:22:53 -0600 |
---|---|---|
committer | Daniel Martà <mvdan@mvdan.cc> | 2018-09-27 07:40:12 +0000 |
commit | 4ba4c5ae795f30f167faef7c15dba3e32afc53d0 (patch) | |
tree | b7365ae830e45064935c3e20d57186e8a0ed5d22 | |
parent | bf70ba07014c15e0b58a308080aa568c8a35f532 (diff) | |
download | go-git-4ba4c5ae795f30f167faef7c15dba3e32afc53d0.tar.gz |
net/http: add http.NotFoundHandler example
Change-Id: I6a69c7a5b829a967d75e1c79210a4906c0d8f505
Reviewed-on: https://go-review.googlesource.com/132276
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
-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)) +} |