Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page iterator #13

Closed
Tracked by #1
jasonjoh opened this issue Nov 3, 2021 · 1 comment · Fixed by #27
Closed
Tracked by #1

Add page iterator #13

jasonjoh opened this issue Nov 3, 2021 · 1 comment · Fixed by #27
Assignees
Labels
enhancement New feature or request Standard GitHub label Issue caused by core project dependency modules or library Status: Fixed

Comments

@jasonjoh
Copy link
Member

jasonjoh commented Nov 3, 2021

https://docs.microsoft.com/en-us/graph/sdks/paging

@baywet baywet added the enhancement New feature or request label Nov 4, 2021
@baywet baywet added this to the Core specification alignment milestone Nov 4, 2021
@baywet baywet added the Standard GitHub label Issue caused by core project dependency modules or library label Nov 8, 2021
@baywet
Copy link
Member

baywet commented Nov 30, 2021

To provide some more context here, it would look something like that for consumers:

client := msgraphsdk.NewGraphServiceClient(adapter)
page1, err := client.Users().Get(&opts)
if err != nil {
    log.Fatal(err)
}
users := make([]graph.User, 0)

iterator := msgraphsdk.NewPageIterator(page1, func (item interface{}) (bool, err) {
    users = append(users, item.(graph.User)) //or anything else you want to do with the item
    return false, nil // boolean is used to tell the iterator to stop before the end of the collection
});
ierator.Iterate(); // this would execute the requests as long as next links are returned, and call the callback for each item in the result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Standard GitHub label Issue caused by core project dependency modules or library Status: Fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants