From 3132e41588dd378ca86582e1f3f9e04ed29dbd28 Mon Sep 17 00:00:00 2001 From: Allan Frese Date: Wed, 5 Aug 2020 10:07:23 +0200 Subject: [PATCH] fixed pagination loop --- src/pd.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pd.go b/src/pd.go index b39cdf0..984ddeb 100644 --- a/src/pd.go +++ b/src/pd.go @@ -167,7 +167,6 @@ INCIDENTS: func pdGetIncidentsSince(since time.Time) []pagerduty.Incident { incidents := make([]pagerduty.Incident, 0) - resp := &pagerduty.ListIncidentsResponse{} opts := pagerduty.ListIncidentsOptions{ Since: since.Format(time.RFC3339), @@ -183,15 +182,16 @@ func pdGetIncidentsSince(since time.Time) []pagerduty.Incident { }, } - for ok := true; ok; ok = resp.APIListObject.More { + ok := true + for ok { log.Printf("API query since: %s, Limit: %v Offset: %v", since, opts.APIListObject.Limit, opts.APIListObject.Offset) resp, err := pd.ListIncidents(opts) if err != nil { log.Println("Error: Cannot list incidents from Pagerduty API:", err) return incidents } + ok = resp.APIListObject.More log.Printf("Got %d incidents", len(resp.Incidents)) - log.Printf("APIListObject %+v", resp.APIListObject) incidents = append(incidents, resp.Incidents...) opts.APIListObject.Offset = opts.APIListObject.Offset + opts.APIListObject.Limit }