Get relevant incident, fix config bug

- Make generic makeRequest fn
This commit is contained in:
Matej Kramny
2015-03-20 19:10:29 +01:00
parent f5826d7832
commit 8e17ebceef
5 changed files with 73 additions and 38 deletions

View File

@@ -2,9 +2,7 @@ package cachet
import (
"fmt"
"bytes"
"strconv"
"net/http"
"encoding/json"
)
@@ -17,21 +15,9 @@ func SendMetric(metricId int, delay int64) {
"value": delay,
})
client := &http.Client{}
req, _ := http.NewRequest("POST", Config.API_Url + "/metrics/" + strconv.Itoa(metricId) + "/points", bytes.NewBuffer(jsonBytes))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Cachet-Token", Config.API_Token)
resp, err := client.Do(req)
if err != nil {
resp, _, err := makeRequest("POST", "/metrics/" + strconv.Itoa(metricId) + "/points", jsonBytes)
if err != nil || resp.StatusCode != 200 {
fmt.Printf("Could not log data point!\n%v\n", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
fmt.Println("Could not log data point!")
}
}