Files
cachet-monitor/cachet/request.go
Matej Kramny 7a5ad278bb Improve fail reasons, fix api crashes
- Add options about TLS verification
- Fix crashes when cachet presents IDs as a string
- Improve fail reasons
2015-07-19 20:25:34 +01:00

33 lines
695 B
Go

package cachet
import (
"bytes"
"crypto/tls"
"io/ioutil"
"net/http"
)
func makeRequest(requestType string, url string, reqBody []byte) (*http.Response, []byte, error) {
req, err := http.NewRequest(requestType, Config.APIUrl+url, bytes.NewBuffer(reqBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Cachet-Token", Config.APIToken)
client := &http.Client{}
if Config.InsecureAPI == true {
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
res, err := client.Do(req)
if err != nil {
return nil, []byte{}, err
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
return res, body, nil
}