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

Commit

Permalink
Retrieve data source by name (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
joanlopez authored Oct 6, 2023
1 parent 93559f4 commit c343a57
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit c343a57

Please sign in to comment.