-
Notifications
You must be signed in to change notification settings - Fork 156
/
boards.go
101 lines (88 loc) · 3.8 KB
/
boards.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Datadog API for Go
*
* Please see the included LICENSE file for licensing information.
*
* Copyright 2019 by authors and contributors.
*/
package datadog
import (
"fmt"
)
// Template variable preset represents a set of template variable values on a dashboard
// Not available to timeboards and screenboards
type TemplateVariablePreset struct {
Name *string `json:"name,omitempty"`
TemplateVariables []TemplateVariablePresetValue `json:"template_variables"`
}
// Template variable preset value represents the value for "name" template variable to assume
type TemplateVariablePresetValue struct {
Name *string `json:"name,omitempty"`
Value *string `json:"value,omitempty"`
}
// Board represents a user created dashboard. This is the full dashboard
// struct when we load a dashboard in detail.
type Board struct {
Title *string `json:"title"`
Widgets []BoardWidget `json:"widgets"`
LayoutType *string `json:"layout_type"`
Id *string `json:"id,omitempty"`
Description *string `json:"description,omitempty"`
TemplateVariables []TemplateVariable `json:"template_variables,omitempty"`
TemplateVariablePresets []TemplateVariablePreset `json:"template_variable_presets,omitempty"`
IsReadOnly *bool `json:"is_read_only,omitempty"`
NotifyList []string `json:"notify_list,omitempty"`
AuthorHandle *string `json:"author_handle,omitempty"`
Url *string `json:"url,omitempty"`
CreatedAt *string `json:"created_at,omitempty"`
ModifiedAt *string `json:"modified_at,omitempty"`
}
// BoardLite represents a simplify dashboard (without widgets, notify list, ...)
// It's used when we load all boards.
type BoardLite struct {
Title *string `json:"title,omitempty"`
Description *string `json:"description,omitempty"`
LayoutType *string `json:"layout_type,omitempty"`
Id *string `json:"id,omitempty"`
Url *string `json:"url,omitempty"`
AuthorHandle *string `json:"author_handle,omitempty"`
IsReadOnly *bool `json:"is_read_only,omitempty"`
CreatedAt *string `json:"created_at,omitempty"`
ModifiedAt *string `json:"modified_at,omitempty"`
}
type reqGetBoards struct {
Boards []BoardLite `json:"dashboards,omitempty"`
}
// GetBoard returns a single dashboard created on this account.
func (client *Client) GetBoard(id string) (*Board, error) {
var board Board
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/dashboard/%s", id), nil, &board); err != nil {
return nil, err
}
return &board, nil
}
// DeleteBoard deletes a dashboard by the identifier.
func (client *Client) DeleteBoard(id string) error {
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/dashboard/%s", id), nil, nil)
}
// CreateBoard creates a new dashboard when given a Board struct.
func (client *Client) CreateBoard(board *Board) (*Board, error) {
var createdBoard Board
if err := client.doJsonRequest("POST", "/v1/dashboard", board, &createdBoard); err != nil {
return nil, err
}
return &createdBoard, nil
}
// UpdateBoard takes a Board struct and persists it back to the server.
// Use this if you've updated your local and need to push it back.
func (client *Client) UpdateBoard(board *Board) error {
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/dashboard/%s", *board.Id), board, nil)
}
// GetBoards returns all Dashboards.
func (client *Client) GetBoards() ([]BoardLite, error) {
var out reqGetBoards
if err := client.doJsonRequest("GET", "/v1/dashboard", nil, &out); err != nil {
return nil, err
}
return out.Boards, nil
}