Skip to content

Commit 502747b

Browse files
committed
fix(codersdk): use url values for query params
1 parent 188b558 commit 502747b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

codersdk/insights.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8+
"net/url"
89
"strings"
910
"time"
1011

@@ -61,18 +62,18 @@ type UserLatencyInsightsRequest struct {
6162
}
6263

6364
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))
6768
if len(req.TemplateIDs) > 0 {
6869
var templateIDs []string
6970
for _, id := range req.TemplateIDs {
7071
templateIDs = append(templateIDs, id.String())
7172
}
72-
qp = append(qp, fmt.Sprintf("template_ids=%s", strings.Join(templateIDs, ",")))
73+
qp.Add("template_ids", strings.Join(templateIDs, ","))
7374
}
7475

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())
7677
resp, err := c.Request(ctx, http.MethodGet, reqURL, nil)
7778
if err != nil {
7879
return UserLatencyInsightsResponse{}, xerrors.Errorf("make request: %w", err)
@@ -158,21 +159,21 @@ type TemplateInsightsRequest struct {
158159
}
159160

160161
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))
164165
if len(req.TemplateIDs) > 0 {
165166
var templateIDs []string
166167
for _, id := range req.TemplateIDs {
167168
templateIDs = append(templateIDs, id.String())
168169
}
169-
qp = append(qp, fmt.Sprintf("template_ids=%s", strings.Join(templateIDs, ",")))
170+
qp.Add("template_ids", strings.Join(templateIDs, ","))
170171
}
171172
if req.Interval != "" {
172-
qp = append(qp, fmt.Sprintf("interval=%s", req.Interval))
173+
qp.Add("interval", string(req.Interval))
173174
}
174175

175-
reqURL := fmt.Sprintf("/api/v2/insights/templates?%s", strings.Join(qp, "&"))
176+
reqURL := fmt.Sprintf("/api/v2/insights/templates?%s", qp.Encode())
176177
resp, err := c.Request(ctx, http.MethodGet, reqURL, nil)
177178
if err != nil {
178179
return TemplateInsightsResponse{}, xerrors.Errorf("make request: %w", err)

0 commit comments

Comments
 (0)