-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindices.go
64 lines (54 loc) · 1.65 KB
/
indices.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
package qweather
import (
"encoding/json"
"fmt"
"net/http"
)
// V7IndicesRequest 天气生活指数请求
type V7IndicesRequest struct {
baseRequest
Location string `json:"location,omitempty"`
Type string `json:"type,omitempty"` // 生活指数的类型ID
Lang string `json:"lang,omitempty"` // 多语言设置
Duration string `json:"duration,omitempty"`
}
func NewV7IndicesRequest() *V7IndicesRequest {
return new(V7IndicesRequest)
}
func (r *V7IndicesRequest) Method() string {
return http.MethodGet
}
func (r *V7IndicesRequest) Url() string {
if r.IsDev {
return fmt.Sprintf("%s/v7/indices/%s", DevApi, r.Duration)
}
return fmt.Sprintf("%s/v7/indices/%s", Api, r.Duration)
}
func (r *V7IndicesRequest) Sting() string {
bs, _ := json.Marshal(r)
return string(bs)
}
// V7IndicesResponse 天气生活指数响应
type V7IndicesResponse struct {
baseResponse
Daily []struct {
Date string `json:"date,omitempty"` // 预报日期
Type string `json:"type,omitempty"` // 生活指数类型ID
Name string `json:"name,omitempty"` // 生活指数类型的名称
Level string `json:"level,omitempty"` // 生活指数预报等级
Category string `json:"category,omitempty"` // 生活指数预报级别名称
Text string `json:"text,omitempty"` // 生活指数预报的详细描述,可能为空
} `json:"daily,omitempty"`
}
func (r *V7IndicesResponse) String() string {
bs, _ := json.Marshal(r)
return string(bs)
}
func (c *Client) V7Indices(req *V7IndicesRequest) (*V7IndicesResponse, error) {
resp := new(V7IndicesResponse)
err := c.Do(req, &resp)
if err != nil {
return nil, err
}
return resp, nil
}