...
Source file
src/net/http/example_handle_test.go
1
2
3
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
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 }
30
View as plain text