瀏覽代碼

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

Brendan Abolivier 7 年之前
父節點
當前提交
a353eb97b1
簽署人: Brendan Abolivier <contact@brendanabolivier.com> GPG 金鑰 ID: 8EF1500759F70623
共有 3 個檔案被更改,包括 6 行新增2 行删除
  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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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
 }