Skip to content

Commit

Permalink
examples: defer inside loop
Browse files Browse the repository at this point in the history
  • Loading branch information
aviau committed Sep 15, 2024
1 parent ebbd0f8 commit 9c29ca1
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions examples/paging-util/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}

0 comments on commit 9c29ca1

Please sign in to comment.