-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (36 loc) · 944 Bytes
/
main.go
File metadata and controls
41 lines (36 loc) · 944 Bytes
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
package main
import (
"log"
"net/http"
"github.com/Nao-Mk2/go-roundtripper-tips/logging"
"github.com/Nao-Mk2/go-roundtripper-tips/mocking"
"github.com/Nao-Mk2/go-roundtripper-tips/retrying"
)
func main() {
// Logging
lc := &http.Client{
Transport: &logging.LoggingTransport{},
}
lc.Get("https://example.com")
// 2021/11/13 00:00:00 GET https://example.com 200 OK
// Mocking
mc := &http.Client{
Transport: &mocking.MockingTransport{},
}
res, _ := mc.Get("https://example.com")
log.Printf("%d %s", res.StatusCode, http.StatusText(res.StatusCode))
// 2021/11/13 00:00:00 200 OK
// or
// 2021/11/13 00:00:00 503 Service Unavailable
// Retrying
rc := &http.Client{
Transport: &retrying.RetryingTransport{
Transport: &logging.LoggingTransport{
Transport: &mocking.MockingTransport{},
},
},
}
rc.Get("https://example.com")
// 2021/11/13 00:00:00 503 Service Unavailable
// 2021/11/13 00:00:01 200 OK
}