-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweather_now.go
75 lines (65 loc) · 1.92 KB
/
weather_now.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
66
67
68
69
70
71
72
73
74
75
package qweather
import (
"encoding/json"
"fmt"
"net/http"
)
// V7WeatherNowRequest 实时天气请求
type V7WeatherNowRequest struct {
baseRequest
Location string `json:"location,omitempty"`
Lang string `json:"lang,omitempty"`
Unit string `json:"unit,omitempty"`
Gzip string `json:"gzip,omitempty"`
}
func NewV7WeatherNowRequest() *V7WeatherNowRequest {
return new(V7WeatherNowRequest)
}
func (r *V7WeatherNowRequest) Method() string {
return http.MethodGet
}
func (r *V7WeatherNowRequest) Url() string {
if r.IsDev {
return fmt.Sprintf("%s/v7/weather/now", DevApi)
}
return fmt.Sprintf("%s/v7/weather/now", Api)
}
func (r *V7WeatherNowRequest) String() string {
bs, _ := json.Marshal(r)
return string(bs)
}
// V7WeatherNowResponse 实时天气响应
type V7WeatherNowResponse struct {
baseResponse
UpdateTime string `json:"updateTime,omitempty"`
FxLink string `json:"fxLink,omitempty"`
Now struct {
ObsTime string `json:"obsTime,omitempty"`
Temp string `json:"temp,omitempty"`
FeelsLike string `json:"feelsLike,omitempty"`
Icon string `json:"icon,omitempty"`
Text string `json:"text,omitempty"`
Wind360 string `json:"wind360,omitempty"`
WindDir string `json:"windDir,omitempty"`
WindScale string `json:"windScale,omitempty"`
WindSpeed string `json:"windSpeed,omitempty"`
Humidity string `json:"humidity,omitempty"`
Precip string `json:"precip,omitempty"`
Pressure string `json:"pressure,omitempty"`
Vis string `json:"vis,omitempty"`
Cloud string `json:"cloud,omitempty"`
Dew string `json:"dew,omitempty"`
} `json:"now,omitempty"`
}
func (r *V7WeatherNowResponse) String() string {
bs, _ := json.Marshal(r)
return string(bs)
}
func (c *Client) V7WeatherNow(req *V7WeatherNowRequest) (*V7WeatherNowResponse, error) {
resp := new(V7WeatherNowResponse)
err := c.Do(req, &resp)
if err != nil {
return nil, err
}
return resp, nil
}