- Add options about TLS verification - Fix crashes when cachet presents IDs as a string - Improve fail reasons
33 lines
695 B
Go
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
|
|
}
|