|
5 | 5 | "encoding/json"
|
6 | 6 | "fmt"
|
7 | 7 | "net/http"
|
| 8 | + "net/url" |
8 | 9 | "strings"
|
9 | 10 | "time"
|
10 | 11 |
|
@@ -61,18 +62,18 @@ type UserLatencyInsightsRequest struct {
|
61 | 62 | }
|
62 | 63 |
|
63 | 64 | func (c *Client) UserLatencyInsights(ctx context.Context, req UserLatencyInsightsRequest) (UserLatencyInsightsResponse, error) {
|
64 |
| - var qp []string |
65 |
| - qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(insightsTimeLayout))) |
66 |
| - qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(insightsTimeLayout))) |
| 65 | + qp := url.Values{} |
| 66 | + qp.Add("start_time", req.StartTime.Format(insightsTimeLayout)) |
| 67 | + qp.Add("end_time", req.EndTime.Format(insightsTimeLayout)) |
67 | 68 | if len(req.TemplateIDs) > 0 {
|
68 | 69 | var templateIDs []string
|
69 | 70 | for _, id := range req.TemplateIDs {
|
70 | 71 | templateIDs = append(templateIDs, id.String())
|
71 | 72 | }
|
72 |
| - qp = append(qp, fmt.Sprintf("template_ids=%s", strings.Join(templateIDs, ","))) |
| 73 | + qp.Add("template_ids", strings.Join(templateIDs, ",")) |
73 | 74 | }
|
74 | 75 |
|
75 |
| - reqURL := fmt.Sprintf("/api/v2/insights/user-latency?%s", strings.Join(qp, "&")) |
| 76 | + reqURL := fmt.Sprintf("/api/v2/insights/user-latency?%s", qp.Encode()) |
76 | 77 | resp, err := c.Request(ctx, http.MethodGet, reqURL, nil)
|
77 | 78 | if err != nil {
|
78 | 79 | return UserLatencyInsightsResponse{}, xerrors.Errorf("make request: %w", err)
|
@@ -158,21 +159,21 @@ type TemplateInsightsRequest struct {
|
158 | 159 | }
|
159 | 160 |
|
160 | 161 | func (c *Client) TemplateInsights(ctx context.Context, req TemplateInsightsRequest) (TemplateInsightsResponse, error) {
|
161 |
| - var qp []string |
162 |
| - qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(insightsTimeLayout))) |
163 |
| - qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(insightsTimeLayout))) |
| 162 | + qp := url.Values{} |
| 163 | + qp.Add("start_time", req.StartTime.Format(insightsTimeLayout)) |
| 164 | + qp.Add("end_time", req.EndTime.Format(insightsTimeLayout)) |
164 | 165 | if len(req.TemplateIDs) > 0 {
|
165 | 166 | var templateIDs []string
|
166 | 167 | for _, id := range req.TemplateIDs {
|
167 | 168 | templateIDs = append(templateIDs, id.String())
|
168 | 169 | }
|
169 |
| - qp = append(qp, fmt.Sprintf("template_ids=%s", strings.Join(templateIDs, ","))) |
| 170 | + qp.Add("template_ids", strings.Join(templateIDs, ",")) |
170 | 171 | }
|
171 | 172 | if req.Interval != "" {
|
172 |
| - qp = append(qp, fmt.Sprintf("interval=%s", req.Interval)) |
| 173 | + qp.Add("interval", string(req.Interval)) |
173 | 174 | }
|
174 | 175 |
|
175 |
| - reqURL := fmt.Sprintf("/api/v2/insights/templates?%s", strings.Join(qp, "&")) |
| 176 | + reqURL := fmt.Sprintf("/api/v2/insights/templates?%s", qp.Encode()) |
176 | 177 | resp, err := c.Request(ctx, http.MethodGet, reqURL, nil)
|
177 | 178 | if err != nil {
|
178 | 179 | return TemplateInsightsResponse{}, xerrors.Errorf("make request: %w", err)
|
|
0 commit comments