mirror of
https://github.com/golang/go
synced 2024-11-23 17:50:06 -07:00
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>
This commit is contained in:
parent
bf70ba0701
commit
4ba4c5ae79
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user