forked from russellcardullo/go-pingdom
-
Notifications
You must be signed in to change notification settings - Fork 7
/
probe.go
41 lines (33 loc) · 820 Bytes
/
probe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package pingdom
import (
"encoding/json"
"io/ioutil"
)
// ProbeService provides an interface to Pingdom probes.
type ProbeService struct {
client *Client
}
// List return a list of probes from Pingdom.
func (cs *ProbeService) List(params ...map[string]string) ([]ProbeResponse, error) {
param := map[string]string{}
if len(params) == 1 {
param = params[0]
}
req, err := cs.client.NewRequest("GET", "/probes", param)
if err != nil {
return nil, err
}
resp, err := cs.client.client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if err := validateResponse(resp); err != nil {
return nil, err
}
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyString := string(bodyBytes)
p := &listProbesJSONResponse{}
err = json.Unmarshal([]byte(bodyString), &p)
return p.Probes, err
}