fix panics
This commit is contained in:
@@ -103,9 +103,7 @@ func (api CachetBackend) NewRequest(requestType, url string, reqBody []byte) (*h
|
|||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
defer req.Body.Close()
|
defer req.Body.Close()
|
||||||
|
|
||||||
var body struct {
|
var body CachetResponse
|
||||||
Data json.RawMessage `json:"data"`
|
|
||||||
}
|
|
||||||
err = json.NewDecoder(res.Body).Decode(&body)
|
err = json.NewDecoder(res.Body).Decode(&body)
|
||||||
|
|
||||||
return res, body, err
|
return res, body, err
|
||||||
@@ -248,7 +246,21 @@ func (api CachetBackend) Tick(monitor monitors.MonitorInterface, status monitors
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api CachetBackend) getComponent(componentID int) (*Component, error) {
|
func (api CachetBackend) getComponent(componentID int) (*Component, error) {
|
||||||
return nil, nil
|
resp, body, err := api.NewRequest("GET", "/components/"+strconv.Itoa(componentID), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var data *Component
|
||||||
|
if err := json.Unmarshal(body.(CachetResponse).Data, &data); err != nil {
|
||||||
|
return nil, fmt.Errorf("Cannot decode component: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, fmt.Errorf("Could not get component! %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api CachetBackend) findIncident(componentID int) (*Incident, error) {
|
func (api CachetBackend) findIncident(componentID int) (*Incident, error) {
|
||||||
@@ -270,7 +282,7 @@ func (api CachetBackend) findIncident(componentID int) (*Incident, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api CachetBackend) findIncidents(componentID int, status int) ([]*Incident, error) {
|
func (api CachetBackend) findIncidents(componentID int, status int) ([]*Incident, error) {
|
||||||
resp, body, err := api.NewRequest("GET", "/incidents?component_id="+strconv.Itoa(componentID)+"&status="+strconv.Itoa(status), nil)
|
resp, body, err := api.NewRequest("GET", "/incidents?component_Id="+strconv.Itoa(componentID)+"&status="+strconv.Itoa(status), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
Execute()
|
|
||||||
}
|
|
||||||
@@ -24,9 +24,7 @@ var rootCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
func main() {
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
||||||
func Execute() {
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ func (monitor *HTTPMonitor) test() (bool, []error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transport := http.DefaultTransport.(*http.Transport)
|
transport := http.DefaultTransport.(*http.Transport)
|
||||||
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: monitor.Strict == false}
|
transport.TLSClientConfig = &tls.Config{
|
||||||
|
InsecureSkipVerify: monitor.Strict == false,
|
||||||
|
}
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Timeout: time.Duration(monitor.Timeout * time.Second),
|
Timeout: time.Duration(monitor.Timeout * time.Second),
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
|
|||||||
Reference in New Issue
Block a user