Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit fb984fc

Browse files
authored
FolderDashboardSearch params: pass in url.Values instead of map (#59)
* allow slices (map[string][]string) in search parameters * add type assert for search params * convert params list element to string, not just assert type * pass in url.Values instead of map * fix test
1 parent 8d1d81f commit fb984fc

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

dashboard.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
"net/url"
78
)
89

910
// DashboardMeta represents Grafana dashboard meta.
@@ -72,8 +73,8 @@ func (c *Client) NewDashboard(dashboard Dashboard) (*DashboardSaveResponse, erro
7273

7374
// Dashboards fetches and returns all dashboards.
7475
func (c *Client) Dashboards() ([]FolderDashboardSearchResponse, error) {
75-
params := map[string]string{
76-
"type": "dash-db",
76+
params := url.Values{
77+
"type": {"dash-db"},
7778
}
7879
return c.FolderDashboardSearch(params)
7980
}
@@ -97,9 +98,9 @@ func (c *Client) DashboardsByIDs(ids []int64) ([]FolderDashboardSearchResponse,
9798
return nil, err
9899
}
99100

100-
params := map[string]string{
101-
"type": "dash-db",
102-
"dashboardIds": string(dashboardIdsJSON),
101+
params := url.Values{
102+
"type": {"dash-db"},
103+
"dashboardIds": {string(dashboardIdsJSON)},
103104
}
104105
return c.FolderDashboardSearch(params)
105106
}

folder_dashboard_search.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ type FolderDashboardSearchResponse struct {
2323

2424
// FolderDashboardSearch uses the folder and dashboard search endpoint to find
2525
// dashboards based on the params passed in.
26-
func (c *Client) FolderDashboardSearch(params map[string]string) (resp []FolderDashboardSearchResponse, err error) {
27-
query := url.Values{}
28-
for p, v := range params {
29-
query.Add(p, v)
30-
}
31-
err = c.request("GET", "/api/search", query, nil, &resp)
26+
func (c *Client) FolderDashboardSearch(params url.Values) (resp []FolderDashboardSearchResponse, err error) {
27+
err = c.request("GET", "/api/search", params, nil, &resp)
3228
return
3329
}

folder_dashboard_search_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gapi
22

33
import (
4+
"net/url"
45
"testing"
56
)
67

@@ -49,7 +50,7 @@ const (
4950
func TestFolderDashboardSearch(t *testing.T) {
5051
server, client := gapiTestTools(t, 200, getFolderDashboardSearchResponse)
5152
defer server.Close()
52-
resp, err := client.FolderDashboardSearch(map[string]string{})
53+
resp, err := client.FolderDashboardSearch(url.Values{})
5354
if err != nil {
5455
t.Fatal(err)
5556
}

0 commit comments

Comments
 (0)