Commit 4ba4c5ae authored by esell's avatar esell Committed by Daniel Martí

net/http: add http.NotFoundHandler example

Change-Id: I6a69c7a5b829a967d75e1c79210a4906c0d8f505
Reviewed-on: https://go-review.googlesource.com/132276Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent bf70ba07
...@@ -173,3 +173,21 @@ func ExampleHandleFunc() { ...@@ -173,3 +173,21 @@ func ExampleHandleFunc() {
log.Fatal(http.ListenAndServe(":8080", nil)) 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))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment