]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: add example for http.HandleFunc
authorDavid Timm <dtimm@pivotal.io>
Thu, 30 Aug 2018 18:25:53 +0000 (12:25 -0600)
committerIan Lance Taylor <iant@golang.org>
Thu, 30 Aug 2018 19:02:30 +0000 (19:02 +0000)
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>
src/net/http/example_test.go

index 53fb0bbb4e104d920dad06d55b1e4c0ea72cd42f..f5c47d0bd4461efaa36ea52478f840112b747ecc 100644 (file)
@@ -159,3 +159,17 @@ func ExampleListenAndServe() {
        http.HandleFunc("/hello", helloHandler)
        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))
+}