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

Commit 4e110c8

Browse files
Allow getting a datasource by its UID (#63)
1 parent 1b82db9 commit 4e110c8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

datasource.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ func (c *Client) DataSource(id int64) (*DataSource, error) {
309309
return result, err
310310
}
311311

312+
// DataSourceByUID fetches and returns the Grafana data source whose UID is passed.
313+
func (c *Client) DataSourceByUID(uid string) (*DataSource, error) {
314+
path := fmt.Sprintf("/api/datasources/uid/%s", uid)
315+
result := &DataSource{}
316+
err := c.request("GET", path, nil, nil, result)
317+
if err != nil {
318+
return nil, err
319+
}
320+
321+
return result, err
322+
}
323+
312324
// DeleteDataSource deletes the Grafana data source whose ID it's passed.
313325
func (c *Client) DeleteDataSource(id int64) error {
314326
path := fmt.Sprintf("/api/datasources/%d", id)

0 commit comments

Comments
 (0)