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

Commit 2aad3cb

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 32e9a51 commit 2aad3cb

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
@@ -87,7 +87,7 @@ func (client UptimeRobotApiClient) GetMonitors() (ms []Monitor, err error) {
8787
offset := 0
8888
data.Add("offset", fmt.Sprintf("%d", offset))
8989

90-
var total float64
90+
var total int
9191

9292
for {
9393
body, err := client.MakeCall(
@@ -174,9 +174,9 @@ func (client UptimeRobotApiClient) GetMonitors() (ms []Monitor, err error) {
174174
ms = append(ms, m)
175175
}
176176

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

0 commit comments

Comments
 (0)