Skip to content

Commit

Permalink
examples: add paging utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aviau committed Sep 15, 2024
1 parent 4294756 commit dbe53a3
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/paging-util/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//go:build go1.23

package main

import (
"fmt"
"os"
"time"

"github.com/Flared/go-flareio"
)

func main() {
client := flareio.NewApiClient(
os.Getenv("FLARE_API_KEY"),
)

fetchedPages := 0

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
fetchedPages = fetchedPages + 1
fmt.Printf(
"Fetched %d page(s) of LeaksDB Sources, next=%s\n",
fetchedPages,
result.Next,
)
}

}

0 comments on commit dbe53a3

Please sign in to comment.