mirror of https://github.com/golang/go.git
net/http: add example for http.HandleFunc
Change-Id: Id0e2fb2abad5b776ac0ed76e55e36c6b774b5b7a Reviewed-on: https://go-review.googlesource.com/132278 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
d3b9572759
commit
0dac1e2e87
|
|
@ -159,3 +159,17 @@ func ExampleListenAndServe() {
|
||||||
http.HandleFunc("/hello", helloHandler)
|
http.HandleFunc("/hello", helloHandler)
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleHandleFunc() {
|
||||||
|
h1 := func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
io.WriteString(w, "Hello from a HandleFunc #1!\n")
|
||||||
|
}
|
||||||
|
h2 := func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
io.WriteString(w, "Hello from a HandleFunc #2!\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
http.HandleFunc("/", h1)
|
||||||
|
http.HandleFunc("/endpoint", h2)
|
||||||
|
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue