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 req.Body.Close()
|
||||
|
||||
var body struct {
|
||||
Data json.RawMessage `json:"data"`
|
||||
}
|
||||
var body CachetResponse
|
||||
err = json.NewDecoder(res.Body).Decode(&body)
|
||||
|
||||
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) {
|
||||
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) {
|
||||
@@ -270,7 +282,7 @@ func (api CachetBackend) findIncident(componentID 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 {
|
||||
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.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
func main() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,9 @@ func (monitor *HTTPMonitor) test() (bool, []error) {
|
||||
}
|
||||
|
||||
transport := http.DefaultTransport.(*http.Transport)
|
||||
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: monitor.Strict == false}
|
||||
transport.TLSClientConfig = &tls.Config{
|
||||
InsecureSkipVerify: monitor.Strict == false,
|
||||
}
|
||||
client := &http.Client{
|
||||
Timeout: time.Duration(monitor.Timeout * time.Second),
|
||||
Transport: transport,
|
||||
|
||||
Reference in New Issue
Block a user