-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_test.go
53 lines (45 loc) · 1.07 KB
/
example_test.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
package httpclient_test
import (
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/hooklift/httpclient"
)
func ExampleDialContext() {
client := &http.Client{
Transport: &http.Transport{
DialContext: httpclient.DialContext(5*time.Second, 5*time.Second),
Proxy: http.ProxyFromEnvironment,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 30 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ResponseHeaderTimeout: 10 * time.Second,
},
}
res, err := client.Get("https://google.com")
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body[:]))
}
func ExampleDefault() {
client := httpclient.Default() // read/write timeout: 30s, connect timeout: 10s
res, err := client.Get("https://google.com")
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body[:]))
}