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

Commit

Permalink
Add folder UID option (#67)
Browse files Browse the repository at this point in the history
Used for grafana/terraform-provider-grafana#323
The existing signature will keep working but an additional argument is supported
  • Loading branch information
julienduchesne authored Mar 4, 2022
1 parent c59af51 commit 0254e2c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ func (c *Client) FolderByUID(uid string) (*Folder, error) {
}

// NewFolder creates a new Grafana folder.
func (c *Client) NewFolder(title string) (Folder, error) {
func (c *Client) NewFolder(title string, uid ...string) (Folder, error) {
if len(uid) > 1 {
return Folder{}, fmt.Errorf("too many arguments. Expected 1 or 2")
}

folder := Folder{}
dataMap := map[string]string{
"title": title,
}
if len(uid) == 1 {
dataMap["uid"] = uid[0]
}
data, err := json.Marshal(dataMap)
if err != nil {
return folder, err
Expand Down

0 comments on commit 0254e2c

Please sign in to comment.