Go
Pagination
One page, every page, or one item at a time.
One page
page, err := client.Threads.List(ctx, openemail.WithFolder("inbox"), openemail.WithLimit(25))if err != nil { return err} for _, thread := range page.Items { fmt.Println(thread.ID())} if page.HasMore { next, err := client.Threads.List(ctx, openemail.WithFolder("inbox"), openemail.WithCursor(page.NextCursor)) if err != nil { return err } fmt.Println(len(next.Items))}A List method returns an *openemail.Page with Items, HasMore and NextCursor. Pass NextCursor back with openemail.WithCursor, with the same filters, to read the next page.
Every page
failed, err := client.Emails.ListAll(ctx, openemail.WithStatus("failed"))if err != nil { return err} fmt.Println(len(failed), "messages failed")A ListAll method follows the cursor to the end and returns every item in one slice. A failure on any page fails the whole call.
One item at a time
for contact, err := range client.Contacts.Iterate(ctx, openemail.WithLimit(100)).All() { if err != nil { return err } if contact.String("email") == "[email protected]" { break }} events := client.Emails.IterateEvents(ctx, "msg_3f9a1c07d2b84e6a9c5b1f20") for events.Next() { fmt.Println(events.Item().String("type"))} return events.Err()An Iterate method returns an *openemail.Iterator, which asks for the next page only when the loop reaches it, so a break stops the requests. Range over All(), or call Next, Item and Err in a plain loop.
An iterator stops when the API repeats a cursor it has already followed, so a walk can never loop for ever.