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

Commit c343a57

Browse files
authored
Retrieve data source by name (#164)
1 parent 93559f4 commit c343a57

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
@@ -95,6 +95,18 @@ func (c *Client) DataSourceByUID(uid string) (*DataSource, error) {
9595
return result, err
9696
}
9797

98+
// DataSourceByName fetches and returns the Grafana data source whose name is passed.
99+
func (c *Client) DataSourceByName(name string) (*DataSource, error) {
100+
path := fmt.Sprintf("/api/datasources/name/%s", name)
101+
result := &DataSource{}
102+
err := c.request("GET", path, nil, nil, result)
103+
if err != nil {
104+
return nil, err
105+
}
106+
107+
return result, err
108+
}
109+
98110
// DataSourceIDByName returns the Grafana data source ID by name.
99111
func (c *Client) DataSourceIDByName(name string) (int64, error) {
100112
path := fmt.Sprintf("/api/datasources/id/%s", name)

0 commit comments

Comments
 (0)