diff options
| author | David Timm <dtimm@pivotal.io> | 2018-08-30 12:25:53 -0600 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2018-08-30 19:02:30 +0000 |
| commit | 0dac1e2e8743476d266a00a81f8bd64400bd8065 (patch) | |
| tree | c0412d23a2da14e483b372afbe48ec50d358a187 /src/net/http/example_test.go | |
| parent | d3b9572759770443d6f89f8e07c1a98eec1cf769 (diff) | |
| download | go-0dac1e2e8743476d266a00a81f8bd64400bd8065.tar.xz | |
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>
Diffstat (limited to 'src/net/http/example_test.go')
| -rw-r--r-- | src/net/http/example_test.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/net/http/example_test.go b/src/net/http/example_test.go index 53fb0bbb4e..f5c47d0bd4 100644 --- a/src/net/http/example_test.go +++ b/src/net/http/example_test.go @@ -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)) +} |
