Skip to content

Commit

Permalink
fix annotations API path string
Browse files Browse the repository at this point in the history
This fixes issue nytm#56
  • Loading branch information
mdb committed Jul 19, 2020
1 parent 249aba6 commit 83c3bae
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type Annotation struct {
IsRegion bool `json:"isRegion,omitempty"`
}

var (
annotationsPath string = "/api/annotations"
)

// GraphiteAnnotation represents a Grafana API annotation in Graphite format
type GraphiteAnnotation struct {
What string `json:"what"`
Expand All @@ -38,7 +42,7 @@ type GraphiteAnnotation struct {
// Annotations fetches the annotations queried with the params it's passed
func (c *Client) Annotations(params url.Values) ([]Annotation, error) {
result := []Annotation{}
err := c.request("GET", "/api/annotation", params, nil, &result)
err := c.request("GET", annotationsPath, params, nil, &result)
if err != nil {
return nil, err
}
Expand All @@ -57,7 +61,7 @@ func (c *Client) NewAnnotation(a *Annotation) (int64, error) {
ID int64 `json:"id"`
}{}

err = c.request("POST", "/api/annotations", nil, bytes.NewBuffer(data), &result)
err = c.request("POST", annotationsPath, nil, bytes.NewBuffer(data), &result)
if err != nil {
return 0, err
}
Expand All @@ -76,7 +80,7 @@ func (c *Client) NewGraphiteAnnotation(gfa *GraphiteAnnotation) (int64, error) {
ID int64 `json:"id"`
}{}

err = c.request("POST", "/api/annotations/graphite", nil, bytes.NewBuffer(data), &result)
err = c.request("POST", annotationsPath+"/graphite", nil, bytes.NewBuffer(data), &result)
if err != nil {
return 0, err
}
Expand All @@ -86,7 +90,7 @@ func (c *Client) NewGraphiteAnnotation(gfa *GraphiteAnnotation) (int64, error) {

// UpdateAnnotation updates all properties an existing annotation with the Annotation it is passed.
func (c *Client) UpdateAnnotation(id int64, a *Annotation) (string, error) {
path := fmt.Sprintf("/api/annotations/%d", id)
path := fmt.Sprintf("%s/%d", annotationsPath, id)
data, err := json.Marshal(a)
if err != nil {
return "", err
Expand All @@ -106,7 +110,7 @@ func (c *Client) UpdateAnnotation(id int64, a *Annotation) (string, error) {

// PatchAnnotation updates one or more properties of an existing annotation that matches the specified ID.
func (c *Client) PatchAnnotation(id int64, a *Annotation) (string, error) {
path := fmt.Sprintf("/api/annotations/%d", id)
path := fmt.Sprintf("%s/%d", annotationsPath, id)
data, err := json.Marshal(a)
if err != nil {
return "", err
Expand All @@ -126,7 +130,7 @@ func (c *Client) PatchAnnotation(id int64, a *Annotation) (string, error) {

// DeleteAnnotation deletes the annotation of the ID it is passed
func (c *Client) DeleteAnnotation(id int64) (string, error) {
path := fmt.Sprintf("/api/annotations/%d", id)
path := fmt.Sprintf("%s/%d", annotationsPath, id)
result := struct {
Message string `json:"message"`
}{}
Expand All @@ -141,7 +145,7 @@ func (c *Client) DeleteAnnotation(id int64) (string, error) {

// DeleteAnnotationByRegionID deletes the annotation corresponding to the region ID it is passed
func (c *Client) DeleteAnnotationByRegionID(id int64) (string, error) {
path := fmt.Sprintf("/api/annotations/region/%d", id)
path := fmt.Sprintf("%s/region/%d", annotationsPath, id)
result := struct {
Message string `json:"message"`
}{}
Expand Down

0 comments on commit 83c3bae

Please sign in to comment.