From 82c45cd735fdbe30c4e40fa1f75ee864d41e6890 Mon Sep 17 00:00:00 2001 From: Jonny Huxtable Date: Mon, 16 Sep 2019 16:43:38 +0100 Subject: [PATCH] Implement read & delete by UID as per Grafana depreciating --- dashboard.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) mode change 100644 => 100755 dashboard.go diff --git a/dashboard.go b/dashboard.go old mode 100644 new mode 100755 index 2d6418f..b5250a7 --- a/dashboard.go +++ b/dashboard.go @@ -93,8 +93,16 @@ func (c *Client) NewDashboard(dashboard Dashboard) (*DashboardSaveResponse, erro return result, err } +// Deprecated: Starting from Grafana v5.0. Please update to use DashboardByUID instead. func (c *Client) Dashboard(slug string) (*Dashboard, error) { - path := fmt.Sprintf("/api/dashboards/db/%s", slug) + return c.dashboard(fmt.Sprintf("/api/dashboards/db/%s", slug)) +} + +func (c *Client) DashboardByUID(uid string) (*Dashboard, error) { + return c.dashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid)) +} + +func (c *Client) dashboard(path string) (*Dashboard, error) { req, err := c.newRequest("GET", path, nil, nil) if err != nil { return nil, err @@ -122,8 +130,16 @@ func (c *Client) Dashboard(slug string) (*Dashboard, error) { return result, err } +// Deprecated: Starting from Grafana v5.0. Please update to use DeleteDashboardByUID instead. func (c *Client) DeleteDashboard(slug string) error { - path := fmt.Sprintf("/api/dashboards/db/%s", slug) + return c.deleteDashboard(fmt.Sprintf("/api/dashboards/db/%s", slug)) +} + +func (c *Client) DeleteDashboardByUID(uid string) error { + return c.deleteDashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid)) +} + +func (c *Client) deleteDashboard(path string) error { req, err := c.newRequest("DELETE", path, nil, nil) if err != nil { return err @@ -138,4 +154,4 @@ func (c *Client) DeleteDashboard(slug string) error { } return nil -} +} \ No newline at end of file