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

Commit 1995720

Browse files
authored
Deprecate UID funcs (#45)
* update deprecation comments, add Uid functions * remove unncessary log * update deprecation string * update test to use Uid * update godoc comments
1 parent c95b50a commit 1995720

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

dashboard.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"io/ioutil"
9-
"log"
109
"net/url"
11-
"os"
1210
)
1311

1412
type DashboardMeta struct {
@@ -48,7 +46,8 @@ type Dashboard struct {
4846
Overwrite bool `json:"overwrite"`
4947
}
5048

51-
// Deprecated: use NewDashboard instead
49+
// SaveDashboard.
50+
// Deprecated: Use NewDashboard instead.
5251
func (c *Client) SaveDashboard(model map[string]interface{}, overwrite bool) (*DashboardSaveResponse, error) {
5352
wrapper := map[string]interface{}{
5453
"dashboard": model,
@@ -137,11 +136,18 @@ func (c *Client) Dashboards() ([]DashboardSearchResponse, error) {
137136
return dashboards, err
138137
}
139138

140-
// Deprecated: Starting from Grafana v5.0. Please update to use DashboardByUID instead.
139+
func (c *Client) DashboardByUid(uid string) (*Dashboard, error) {
140+
return c.dashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
141+
}
142+
143+
// Dashboard will be removed.
144+
// Deprecated: Starting from Grafana v5.0. Use DashboardByUid instead.
141145
func (c *Client) Dashboard(slug string) (*Dashboard, error) {
142146
return c.dashboard(fmt.Sprintf("/api/dashboards/db/%s", slug))
143147
}
144148

149+
// DashboardByUID will be removed.
150+
// Deprecated: Interface typo. Use DashboardByUid instead.
145151
func (c *Client) DashboardByUID(uid string) (*Dashboard, error) {
146152
return c.dashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
147153
}
@@ -168,17 +174,22 @@ func (c *Client) dashboard(path string) (*Dashboard, error) {
168174
result := &Dashboard{}
169175
err = json.Unmarshal(data, &result)
170176
result.Folder = result.Meta.Folder
171-
if os.Getenv("GF_LOG") != "" {
172-
log.Printf("got back dashboard response %s", data)
173-
}
177+
174178
return result, err
175179
}
176180

177-
// Deprecated: Starting from Grafana v5.0. Please update to use DeleteDashboardByUID instead.
181+
func (c *Client) DeleteDashboardByUid(uid string) error {
182+
return c.deleteDashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
183+
}
184+
185+
// DeleteDashboard will be removed.
186+
// Deprecated: Starting from Grafana v5.0. Use DeleteDashboardByUid instead.
178187
func (c *Client) DeleteDashboard(slug string) error {
179188
return c.deleteDashboard(fmt.Sprintf("/api/dashboards/db/%s", slug))
180189
}
181190

191+
// DeleteDashboardByUID will be removed.
192+
// Deprecated: Interface typo. Use DeleteDashboardByUid instead.
182193
func (c *Client) DeleteDashboardByUID(uid string) error {
183194
return c.deleteDashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
184195
}

dashboard_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestDashboardGet(t *testing.T) {
8989
t.Errorf("Invalid uid - %s, Expected %s", uid, "cIBgcSjkk")
9090
}
9191

92-
resp, err = client.DashboardByUID("cIBgcSjkk")
92+
resp, err = client.DashboardByUid("cIBgcSjkk")
9393
if err != nil {
9494
t.Error(err)
9595
}
@@ -105,7 +105,7 @@ func TestDashboardGet(t *testing.T) {
105105
t.Errorf("%d not detected", code)
106106
}
107107

108-
_, err = client.DashboardByUID("cIBgcSjkk")
108+
_, err = client.DashboardByUid("cIBgcSjkk")
109109
if err == nil {
110110
t.Errorf("%d not detected", code)
111111
}
@@ -121,7 +121,7 @@ func TestDashboardDelete(t *testing.T) {
121121
t.Error(err)
122122
}
123123

124-
err = client.DeleteDashboardByUID("cIBgcSjkk")
124+
err = client.DeleteDashboardByUid("cIBgcSjkk")
125125
if err != nil {
126126
t.Error(err)
127127
}
@@ -134,7 +134,7 @@ func TestDashboardDelete(t *testing.T) {
134134
t.Errorf("%d not detected", code)
135135
}
136136

137-
err = client.DeleteDashboardByUID("cIBgcSjkk")
137+
err = client.DeleteDashboardByUid("cIBgcSjkk")
138138
if err == nil {
139139
t.Errorf("%d not detected", code)
140140
}

datasource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ type DataSource struct {
1717

1818
Database string `json:"database,omitempty"`
1919
User string `json:"user,omitempty"`
20-
// Deprecated in favor of secureJsonData.password
20+
// Deprecated: Use secureJsonData.password instead.
2121
Password string `json:"password,omitempty"`
2222

2323
OrgId int64 `json:"orgId,omitempty"`
2424
IsDefault bool `json:"isDefault"`
2525

2626
BasicAuth bool `json:"basicAuth"`
2727
BasicAuthUser string `json:"basicAuthUser,omitempty"`
28-
// Deprecated in favor of secureJsonData.basicAuthPassword
28+
// Deprecated: Use secureJsonData.basicAuthPassword instead.
2929
BasicAuthPassword string `json:"basicAuthPassword,omitempty"`
3030

3131
JSONData JSONData `json:"jsonData,omitempty"`

0 commit comments

Comments
 (0)