We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent de72c43 commit 3ee9672Copy full SHA for 3ee9672
src/net/http/example_handle_test.go
@@ -0,0 +1,29 @@
1
+// Copyright 2018 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package http_test
6
7
+import (
8
+ "fmt"
9
+ "log"
10
+ "net/http"
11
+ "sync"
12
+)
13
14
+type countHandler struct {
15
+ mu sync.Mutex // guards n
16
+ n int
17
+}
18
19
+func (h *countHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
20
+ h.mu.Lock()
21
+ defer h.mu.Unlock()
22
+ h.n++
23
+ fmt.Fprintf(w, "count is %d\n", h.n)
24
25
26
+func ExampleHandle() {
27
+ http.Handle("/count", new(countHandler))
28
+ log.Fatal(http.ListenAndServe(":8080", nil))
29
0 commit comments