Ver código fonte

Add Content-Type header for non-GET HTTP requests + rename function for more accuracy

Brendan Abolivier 6 anos atrás
pai
commit
a353eb97b1
Assinado por: Brendan Abolivier <contact@brendanabolivier.com> ID da chave GPG: 8EF1500759F70623
3 arquivos alterados com 6 adições e 2 exclusões
  1. 4
    0
      src/grafana/client.go
  2. 1
    1
      src/grafana/dashboards.go
  3. 1
    1
      src/pusher/webhook.go

+ 4
- 0
src/grafana/client.go Ver arquivo

@@ -37,6 +37,10 @@ func (c *Client) request(method string, endpoint string, body []byte) ([]byte, e
37 37
 	authHeader := fmt.Sprintf("Bearer %s", c.APIKey)
38 38
 	req.Header.Add("Authorization", authHeader)
39 39
 
40
+	if method != "GET" {
41
+		req.Header.Add("Content-Type", "application/json")
42
+	}
43
+
40 44
 	resp, err := c.httpClient.Do(req)
41 45
 	if err != nil {
42 46
 		return nil, err

+ 1
- 1
src/grafana/dashboards.go Ver arquivo

@@ -77,7 +77,7 @@ func (c *Client) GetDashboard(URI string) (db *Dashboard, err error) {
77 77
 	return
78 78
 }
79 79
 
80
-func (c *Client) UpdateDashboard(slug string, contentJSON []byte) (err error) {
80
+func (c *Client) CreateOrUpdateDashboard(slug string, contentJSON []byte) (err error) {
81 81
 	reqBody := dbUpdateRequest{
82 82
 		Dashboard: rawJSON(contentJSON),
83 83
 		Overwrite: false,

+ 1
- 1
src/pusher/webhook.go Ver arquivo

@@ -73,5 +73,5 @@ func pushFile(filename string) error {
73 73
 	// Remove the .json part
74 74
 	slug := strings.Split(filename, ".json")[0]
75 75
 
76
-	return grafanaClient.UpdateDashboard(slug, fileContent)
76
+	return grafanaClient.CreateOrUpdateDashboard(slug, fileContent)
77 77
 }