forked from AntoineAugusti/updown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdowntimes.go
44 lines (37 loc) · 952 Bytes
/
downtimes.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
42
43
44
package updown
import (
"fmt"
"net/http"
"strconv"
)
// Downtime represents a downtime period for a check
type Downtime struct {
Error string `json:"error,omitempty"`
StartedAt string `json:"started_at,omitempty"`
EndedAt string `json:"ended_at,omitempty"`
Duration int `json:"duration,omitempty"`
}
// DowntimeService interacts with the downtimes section of the API
type DowntimeService struct {
client *Client
}
// List lists all known downtimes for a check
func (s *DowntimeService) List(token string, pageNb int) ([]Downtime, *http.Response, error) {
path := fmt.Sprintf("checks/%s/downtimes?page=%s", token, strconv.Itoa(max(1, pageNb)))
req, err := s.client.NewRequest("GET", path, nil)
if err != nil {
return nil, nil, err
}
var res []Downtime
resp, err := s.client.Do(req, &res)
if err != nil {
return nil, resp, err
}
return res, resp, err
}
func max(a, b int) int {
if a > b {
return a
}
return b
}