From dbe53a3148cd630b1f472b27cf33c9a742acdc77 Mon Sep 17 00:00:00 2001 From: aviau Date: Sun, 15 Sep 2024 12:36:19 -0400 Subject: [PATCH] examples: add paging utils --- examples/paging-util/main.go | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/paging-util/main.go diff --git a/examples/paging-util/main.go b/examples/paging-util/main.go new file mode 100644 index 0000000..0b2bbf2 --- /dev/null +++ b/examples/paging-util/main.go @@ -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, + ) + } + +}