-
Notifications
You must be signed in to change notification settings - Fork 33
/
graph_annotation.go
51 lines (44 loc) · 1.77 KB
/
graph_annotation.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
package mackerel
import (
"fmt"
"net/url"
"strconv"
)
// GraphAnnotation represents parameters to post a graph annotation.
type GraphAnnotation struct {
ID string `json:"id,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
From int64 `json:"from,omitempty"`
To int64 `json:"to,omitempty"`
Service string `json:"service,omitempty"`
Roles []string `json:"roles,omitempty"`
}
// FindGraphAnnotations fetches graph annotations.
func (c *Client) FindGraphAnnotations(service string, from int64, to int64) ([]*GraphAnnotation, error) {
params := url.Values{}
params.Add("service", service)
params.Add("from", strconv.FormatInt(from, 10))
params.Add("to", strconv.FormatInt(to, 10))
data, err := requestGetWithParams[struct {
GraphAnnotations []*GraphAnnotation `json:"graphAnnotations"`
}](c, "/api/v0/graph-annotations", params)
if err != nil {
return nil, err
}
return data.GraphAnnotations, nil
}
// CreateGraphAnnotation creates a graph annotation.
func (c *Client) CreateGraphAnnotation(annotation *GraphAnnotation) (*GraphAnnotation, error) {
return requestPost[GraphAnnotation](c, "/api/v0/graph-annotations", annotation)
}
// UpdateGraphAnnotation updates a graph annotation.
func (c *Client) UpdateGraphAnnotation(annotationID string, annotation *GraphAnnotation) (*GraphAnnotation, error) {
path := fmt.Sprintf("/api/v0/graph-annotations/%s", annotationID)
return requestPut[GraphAnnotation](c, path, annotation)
}
// DeleteGraphAnnotation deletes a graph annotation.
func (c *Client) DeleteGraphAnnotation(annotationID string) (*GraphAnnotation, error) {
path := fmt.Sprintf("/api/v0/graph-annotations/%s", annotationID)
return requestDelete[GraphAnnotation](c, path)
}