diff --git a/examples/paging-util/main.go b/examples/paging-util/main.go index 369db70..08de8c1 100644 --- a/examples/paging-util/main.go +++ b/examples/paging-util/main.go @@ -20,24 +20,26 @@ func main() { for result, err := range client.IterGet( "/leaksdb/v2/sources", nil, ) { - // Rate Limiting - time.Sleep(time.Second * 1) - - if err != nil { - fmt.Printf("unexpected error: %s\n", err) - os.Exit(1) - } - - // Handle the response - // ... - - // Print the status - fetchedPages = fetchedPages + 1 - fmt.Printf( - "Fetched %d page(s) of LeaksDB Sources, next=%s\n", - fetchedPages, - result.Next, - ) + func(result *flareio.IterResult, err error) { + // Rate Limiting + time.Sleep(time.Second * 1) + + if err != nil { + fmt.Printf("unexpected error: %s\n", err) + os.Exit(1) + } + + // Handle the response... + defer result.Response.Body.Close() + + // Print the status + fetchedPages = fetchedPages + 1 + fmt.Printf( + "Fetched %d page(s) of LeaksDB Sources, next=%s\n", + fetchedPages, + result.Next, + ) + }(result, err) } }