|
@@ -5,6 +5,8 @@ import (
|
5
|
5
|
"fmt"
|
6
|
6
|
)
|
7
|
7
|
|
|
8
|
+
|
|
9
|
+
|
8
|
10
|
type dbSearchResponse struct {
|
9
|
11
|
ID int `json:"id"`
|
10
|
12
|
Title string `json:"title"`
|
|
@@ -14,24 +16,36 @@ type dbSearchResponse struct {
|
14
|
16
|
Starred bool `json:"isStarred"`
|
15
|
17
|
}
|
16
|
18
|
|
17
|
|
-type dbUpdateRequest struct {
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+type dbCreateOrUpdateRequest struct {
|
18
|
22
|
Dashboard rawJSON `json:"dashboard"`
|
19
|
23
|
Overwrite bool `json:"overwrite"`
|
20
|
24
|
}
|
21
|
25
|
|
22
|
|
-type dbUpdateResponse struct {
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+type dbCreateOrUpdateResponse struct {
|
23
|
31
|
Status string `json:"success"`
|
24
|
32
|
Version int `json:"version,omitempty"`
|
25
|
33
|
Message string `json:"message,omitempty"`
|
26
|
34
|
}
|
27
|
35
|
|
|
36
|
+
|
|
37
|
+
|
28
|
38
|
type Dashboard struct {
|
29
|
39
|
RawJSON []byte
|
30
|
40
|
Slug string
|
31
|
41
|
Version int
|
32
|
42
|
}
|
33
|
43
|
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
34
|
47
|
func (d *Dashboard) UnmarshalJSON(b []byte) (err error) {
|
|
48
|
+
|
35
|
49
|
var body struct {
|
36
|
50
|
Dashboard rawJSON `json:"dashboard"`
|
37
|
51
|
Meta struct {
|
|
@@ -40,9 +54,11 @@ func (d *Dashboard) UnmarshalJSON(b []byte) (err error) {
|
40
|
54
|
} `json:"meta"`
|
41
|
55
|
}
|
42
|
56
|
|
|
57
|
+
|
43
|
58
|
if err = json.Unmarshal(b, &body); err != nil {
|
44
|
59
|
return
|
45
|
60
|
}
|
|
61
|
+
|
46
|
62
|
d.Slug = body.Meta.Slug
|
47
|
63
|
d.Version = body.Meta.Version
|
48
|
64
|
d.RawJSON = body.Dashboard
|
|
@@ -50,6 +66,10 @@ func (d *Dashboard) UnmarshalJSON(b []byte) (err error) {
|
50
|
66
|
return
|
51
|
67
|
}
|
52
|
68
|
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
53
|
73
|
func (c *Client) GetDashboardsURIs() (URIs []string, err error) {
|
54
|
74
|
resp, err := c.request("GET", "search", nil)
|
55
|
75
|
|
|
@@ -66,6 +86,11 @@ func (c *Client) GetDashboardsURIs() (URIs []string, err error) {
|
66
|
86
|
return
|
67
|
87
|
}
|
68
|
88
|
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
69
|
94
|
func (c *Client) GetDashboard(URI string) (db *Dashboard, err error) {
|
70
|
95
|
body, err := c.request("GET", "dashboards/"+URI, nil)
|
71
|
96
|
if err != nil {
|
|
@@ -77,8 +102,18 @@ func (c *Client) GetDashboard(URI string) (db *Dashboard, err error) {
|
77
|
102
|
return
|
78
|
103
|
}
|
79
|
104
|
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
80
|
115
|
func (c *Client) CreateOrUpdateDashboard(slug string, contentJSON []byte) (err error) {
|
81
|
|
- reqBody := dbUpdateRequest{
|
|
116
|
+ reqBody := dbCreateOrUpdateRequest{
|
82
|
117
|
Dashboard: rawJSON(contentJSON),
|
83
|
118
|
Overwrite: true,
|
84
|
119
|
}
|
|
@@ -99,7 +134,7 @@ func (c *Client) CreateOrUpdateDashboard(slug string, contentJSON []byte) (err e
|
99
|
134
|
}
|
100
|
135
|
}
|
101
|
136
|
|
102
|
|
- var respBody dbUpdateResponse
|
|
137
|
+ var respBody dbCreateOrUpdateResponse
|
103
|
138
|
if err = json.Unmarshal(respBodyJSON, &respBody); err != nil {
|
104
|
139
|
return
|
105
|
140
|
}
|