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

Retrieve data source by name #164

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ func (c *Client) DataSourceByUID(uid string) (*DataSource, error) {
return result, err
}

// DataSourceByName fetches and returns the Grafana data source whose name is passed.
func (c *Client) DataSourceByName(name string) (*DataSource, error) {
path := fmt.Sprintf("/api/datasources/name/%s", name)
result := &DataSource{}
err := c.request("GET", path, nil, nil, result)
if err != nil {
return nil, err
}

return result, err
}

// DataSourceIDByName returns the Grafana data source ID by name.
func (c *Client) DataSourceIDByName(name string) (int64, error) {
path := fmt.Sprintf("/api/datasources/id/%s", name)
Expand Down