forked from dgrr/http2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (47 loc) · 1.03 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
55
56
57
58
59
60
61
62
63
package main
import (
"encoding/json"
"fmt"
"log"
"sync"
"github.com/ip-rw/http2/fasthttp2"
"github.com/valyala/fasthttp"
)
func main() {
c := &fasthttp.HostClient{
Addr: "api.binance.com:443",
IsTLS: true,
}
if err := fasthttp2.ConfigureClient(c); err != nil {
panic(err)
}
var wg sync.WaitGroup
for i := 0; i < 5; i++ {
wg.Add(1)
go func() {
defer wg.Done()
req := fasthttp.AcquireRequest()
res := fasthttp.AcquireResponse()
res.Reset()
req.Header.SetMethod("GET")
// TODO: Use SetRequestURI
req.URI().Update("https://api.binance.com/api/v3/exchangeInfo")
err := c.Do(req, res)
if err != nil {
log.Fatalln(err)
}
body := res.Body()
fmt.Printf("%d: %d\n", res.Header.StatusCode(), len(body))
res.Header.VisitAll(func(k, v []byte) {
fmt.Printf("%s: %s\n", k, v)
})
a := make(map[string]interface{})
if err = json.Unmarshal(body, &a); err != nil {
panic(err)
}
fmt.Println("------------------------")
}()
}
wg.Wait()
// fmt.Printf("%s\n", body)
}