-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtop_city.go
66 lines (56 loc) · 1.54 KB
/
top_city.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
package qweather
import (
"encoding/json"
"fmt"
"net/http"
)
// V2TopCityRequest 热门城市查询请求
type V2TopCityRequest struct {
baseRequest
Range string `json:"range,omitempty"`
Number int `json:"number,omitempty"`
Lang string `json:"lang,omitempty"`
}
func NewV2TopCityRequest() *V2TopCityRequest {
return new(V2TopCityRequest)
}
func (*V2TopCityRequest) Method() string {
return http.MethodGet
}
func (*V2TopCityRequest) Url() string {
return fmt.Sprintf("%s/v2/city/top", GeoApi)
}
func (r *V2TopCityRequest) String() string {
bs, _ := json.Marshal(r)
return string(bs)
}
// V2CityTopResponse 热门城市查询响应
type V2CityTopResponse struct {
baseResponse
TopCityList []struct {
Name string `json:"name,omitempty"`
Id string `json:"id,omitempty"`
Lat string `json:"lat,omitempty"`
Lon string `json:"lon,omitempty"`
Adm2 string `json:"adm2,omitempty"`
Adm1 string `json:"adm1,omitempty"`
Country string `json:"country,omitempty"`
UtcOffset string `json:"utcOffset,omitempty"`
IsDst string `json:"isDst,omitempty"`
Type string `json:"type,omitempty"`
Rank string `json:"rank,omitempty"`
FxLink string `json:"fxLink,omitempty"`
} `json:"topCityList,omitempty"`
}
func (r *V2CityTopResponse) String() string {
bs, _ := json.Marshal(r)
return string(bs)
}
func (c *Client) V2TopCity(req *V2TopCityRequest) (*V2CityTopResponse, error) {
resp := new(V2CityTopResponse)
err := c.Do(req, &resp)
if err != nil {
return nil, err
}
return resp, nil
}