@@ -30,6 +30,10 @@ import (
30
30
"github.com/pkg/errors"
31
31
)
32
32
33
+ // DefaultFolderId is the id of the general folder
34
+ // that is pre-created and cannot be removed.
35
+ const DefaultFolderId = 0
36
+
33
37
// BoardProperties keeps metadata of a dashboard.
34
38
type BoardProperties struct {
35
39
IsStarred bool `json:"isStarred,omitempty"`
@@ -193,6 +197,13 @@ func (r *Client) SearchDashboards(query string, starred bool, tags ...string) ([
193
197
return boards , err
194
198
}
195
199
200
+ // SetDashboardParams contains the extra parameteres
201
+ // that affects where and how the dashboard will be stored
202
+ type SetDashboardParams struct {
203
+ FolderID int
204
+ Overwrite bool
205
+ }
206
+
196
207
// SetDashboard updates existing dashboard or creates a new one.
197
208
// Set dasboard ID to nil to create a new dashboard.
198
209
// Set overwrite to true if you want to overwrite existing dashboard with
@@ -201,11 +212,12 @@ func (r *Client) SearchDashboards(query string, starred bool, tags ...string) ([
201
212
// may be only loaded with HTTP API but not created or updated.
202
213
//
203
214
// Reflects POST /api/dashboards/db API call.
204
- func (r * Client ) SetDashboard (board Board , overwrite bool ) (StatusMessage , error ) {
215
+ func (r * Client ) SetDashboard (board Board , params SetDashboardParams ) (StatusMessage , error ) {
205
216
var (
206
217
isBoardFromDB bool
207
218
newBoard struct {
208
219
Dashboard Board `json:"dashboard"`
220
+ FolderID int `json:"folderId"`
209
221
Overwrite bool `json:"overwrite"`
210
222
}
211
223
raw []byte
@@ -217,8 +229,9 @@ func (r *Client) SetDashboard(board Board, overwrite bool) (StatusMessage, error
217
229
return StatusMessage {}, errors .New ("only database dashboard (with 'db/' prefix in a slug) can be set" )
218
230
}
219
231
newBoard .Dashboard = board
220
- newBoard .Overwrite = overwrite
221
- if ! overwrite {
232
+ newBoard .FolderID = params .FolderID
233
+ newBoard .Overwrite = params .Overwrite
234
+ if ! params .Overwrite {
222
235
newBoard .Dashboard .ID = 0
223
236
}
224
237
if raw , err = json .Marshal (newBoard ); err != nil {
0 commit comments