forked from gsamokovarov/sg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
39 lines (33 loc) · 852 Bytes
/
trace.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
package sg
import (
"net/http"
"net/http/httputil"
)
// Tracer is the implementation of a tracer that can print debug information of
// a Client SendGrid API requests and responses. Setting a tracer on the client
// can help us debug errors.
//
// The standard Logger implements this interface.
type Tracer interface {
Printf(string, ...interface{})
}
var dumpRequest = func(t Tracer, request *http.Request) {
if t == nil {
return
}
if dump, err := httputil.DumpRequest(request, true); err == nil {
t.Printf("\nRequest\n%s\n", dump)
} else {
t.Printf("\nRequest\n%s\n", request)
}
}
var dumpResponse = func(t Tracer, response *http.Response) {
if t == nil {
return
}
if dump, err := httputil.DumpResponse(response, true); err == nil {
t.Printf("\nReponse\n%s\n", dump)
} else {
t.Printf("\nResponse\n%s\n", response)
}
}