Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 5aaccba

Browse files
jleehmlclmj
authored andcommitted
Implement read & delete by UID as per Grafana depreciating (#25)
1 parent bd4e74c commit 5aaccba

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

dashboard.go

100644100755
+19-3
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,16 @@ func (c *Client) NewDashboard(dashboard Dashboard) (*DashboardSaveResponse, erro
9393
return result, err
9494
}
9595

96+
// Deprecated: Starting from Grafana v5.0. Please update to use DashboardByUID instead.
9697
func (c *Client) Dashboard(slug string) (*Dashboard, error) {
97-
path := fmt.Sprintf("/api/dashboards/db/%s", slug)
98+
return c.dashboard(fmt.Sprintf("/api/dashboards/db/%s", slug))
99+
}
100+
101+
func (c *Client) DashboardByUID(uid string) (*Dashboard, error) {
102+
return c.dashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
103+
}
104+
105+
func (c *Client) dashboard(path string) (*Dashboard, error) {
98106
req, err := c.newRequest("GET", path, nil, nil)
99107
if err != nil {
100108
return nil, err
@@ -122,8 +130,16 @@ func (c *Client) Dashboard(slug string) (*Dashboard, error) {
122130
return result, err
123131
}
124132

133+
// Deprecated: Starting from Grafana v5.0. Please update to use DeleteDashboardByUID instead.
125134
func (c *Client) DeleteDashboard(slug string) error {
126-
path := fmt.Sprintf("/api/dashboards/db/%s", slug)
135+
return c.deleteDashboard(fmt.Sprintf("/api/dashboards/db/%s", slug))
136+
}
137+
138+
func (c *Client) DeleteDashboardByUID(uid string) error {
139+
return c.deleteDashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
140+
}
141+
142+
func (c *Client) deleteDashboard(path string) error {
127143
req, err := c.newRequest("DELETE", path, nil, nil)
128144
if err != nil {
129145
return err
@@ -138,4 +154,4 @@ func (c *Client) DeleteDashboard(slug string) error {
138154
}
139155

140156
return nil
141-
}
157+
}

0 commit comments

Comments
 (0)