Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

fix annotations API path string #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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