forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshot.go
36 lines (30 loc) · 866 Bytes
/
snapshot.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
package gapi
import (
"encoding/json"
)
// Snapshot represents a Grafana snapshot.
type Snapshot struct {
Model map[string]interface{} `json:"dashboard"`
Expires int64 `json:"expires"`
}
// SnapshotResponse represents the Grafana API response to creating a dashboard.
type SnapshotCreateResponse struct {
DeleteKey string `json:"deleteKey"`
DeleteURL string `json:"deleteUrl"`
Key string `json:"key"`
URL string `json:"url"`
ID int64 `json:"id"`
}
// NewSnapshot creates a new Grafana snapshot.
func (c *Client) NewSnapshot(snapshot Snapshot) (*SnapshotCreateResponse, error) {
data, err := json.Marshal(snapshot)
if err != nil {
return nil, err
}
result := &SnapshotCreateResponse{}
err = c.request("POST", "/api/snapshots", nil, data, &result)
if err != nil {
return nil, err
}
return result, err
}