-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
47 lines (36 loc) · 821 Bytes
/
example.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
package main
import (
"fmt"
"github.com/sguessou/go-httpclient/gohttp"
)
var (
httpClient = getGithubClient()
)
func getGithubClient() gohttp.Client {
client := gohttp.
NewBuilder().
Build()
// client.SetMaxIdleconnections(20)
// client.SetConnectionTimeout(2 * time.Second)
// client.SetResponseTimeout(4 * time.Millisecond)
// commonHeaders := make(http.Header)
// commonHeaders.Set("Authorization", "Bearer abc-124")
// client.SetHeaders(commonHeaders)
return client
}
type User struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
func main() {
getUrls()
}
func getUrls() {
resp, err := httpClient.Get("https://api.github.com", nil)
if err != nil {
panic(err)
}
fmt.Println(resp.Status())
fmt.Println(resp.StatusCode())
fmt.Println(resp.String())
}