Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit 1176116

Browse files
committed
Break monitors loop when page offset is greater than monitor records
Compare page offset to total monitor records to know when to break from loop. This will avoid infinit loops in situations where a monitor gets added/removed mid-call.
1 parent effa054 commit 1176116

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

uptimerobot/api/monitor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (client UptimeRobotApiClient) GetMonitors() (ms []Monitor, err error) {
8989
offset := 0
9090
data.Add("offset", fmt.Sprintf("%d", offset))
9191

92-
var total float64
92+
var total int
9393

9494
for {
9595
body, err := client.MakeCall(
@@ -176,9 +176,9 @@ func (client UptimeRobotApiClient) GetMonitors() (ms []Monitor, err error) {
176176
ms = append(ms, m)
177177
}
178178

179-
total = body["pagination"].(map[string]interface{})["total"].(float64)
180-
if float64(len(ms)) != total {
181-
offset += maxMonitorRecords
179+
total = int(body["pagination"].(map[string]interface{})["total"].(float64))
180+
offset += maxMonitorRecords
181+
if offset < total {
182182
data.Set("offset", fmt.Sprintf("%d", offset))
183183
} else {
184184
break

0 commit comments

Comments
 (0)