-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
54 lines (45 loc) · 1.15 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"github.com/deferpanic/deferclient/deferstats"
"io/ioutil"
"net/http"
"time"
)
// fast test
func fastHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "this request is fast")
resp, err := http.Get("http://test.deferpanic.net")
if err != nil {
fmt.Fprintf(w, err.Error())
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Fprintf(w, err.Error())
return
}
if len(body) != 0 {
fmt.Fprintf(w, string(body))
}
}
// slow test
func slowHandler(w http.ResponseWriter, r *http.Request) {
time.Sleep(6 * time.Second)
fmt.Fprintf(w, "this request is slow")
}
// panic test
func panicHandler(w http.ResponseWriter, r *http.Request) {
panic("There is no need for panic")
fmt.Fprintf(w, "this request is panic")
}
func main() {
dps := deferstats.NewClient("z57z3xsEfpqxpr0dSte0auTBItWBYa1c")
go dps.CaptureStats()
// no need to change these?
http.HandleFunc("/fast", dps.HTTPHandlerFunc(fastHandler))
http.HandleFunc("/slow", dps.HTTPHandlerFunc(slowHandler))
http.HandleFunc("/panic", dps.HTTPHandlerFunc(panicHandler))
http.ListenAndServe(":3000", nil)
}