-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (60 loc) · 1.92 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
64
65
package main
import (
"encoding/json"
"fmt"
"github.com/go-resty/resty/v2"
"github.com/ysk229/pro-http-clinet/pb/proto/api/weather/v1"
"log"
)
func main() {
client := resty.New()
var req = weather.Request{Key: "SCYrvkytJze9qyzOh", Location: "be"}
err := req.Validate()
if err != nil {
fmt.Println("err", err)
}
resp, err := client.R().
SetQueryParams(map[string]string{
"key": req.GetKey(),
"location": req.GetLocation(),
}).
SetHeader("Accept", "application/json").
Get("https://api.seniverse.com/v3/weather/daily.json?language=zh-Hans&unit=c")
rst := &weather.Reply{}
err = json.Unmarshal(resp.Body(), rst)
//err = proto.Unmarshal(resp.Body(),rst )
if err != nil {
log.Fatal("unmarshaling error: ", err)
}
for _, item := range rst.Results {
//log.Println(item)
log.Println(item.Location.Id)
log.Println(item.Location.Name)
}
//
//// Explore response object
//fmt.Println("Response Info:")
fmt.Println(" Error :", err)
//fmt.Println(" Status Code:", resp.StatusCode())
//fmt.Println(" Status :", resp.Status())
//fmt.Println(" Proto :", resp.Proto())
//fmt.Println(" Time :", resp.Time())
//fmt.Println(" Received At:", resp.ReceivedAt())
//fmt.Println(" Body :\n", resp)
//fmt.Println()
//
//// Explore trace info
//fmt.Println("Request Trace Info:")
//ti := resp.Request.TraceInfo()
//fmt.Println(" DNSLookup :", ti.DNSLookup)
//fmt.Println(" ConnTime :", ti.ConnTime)
//fmt.Println(" TCPConnTime :", ti.TCPConnTime)
//fmt.Println(" TLSHandshake :", ti.TLSHandshake)
//fmt.Println(" ServerTime :", ti.ServerTime)
//fmt.Println(" ResponseTime :", ti.ResponseTime)
//fmt.Println(" TotalTime :", ti.TotalTime)
//fmt.Println(" IsConnReused :", ti.IsConnReused)
//fmt.Println(" IsConnWasIdle :", ti.IsConnWasIdle)
//fmt.Println(" ConnIdleTime :", ti.ConnIdleTime)
//fmt.Println(" RequestAttempt:", ti.RequestAttempt)
}