From fab0662d46a9f2e23e0f28066102b8ff7545cbf3 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 4 Jun 2014 00:26:19 -0700 Subject: [PATCH] Add pagination section to docs. First draft, suggestions for improvements are welcome. The snippet should serve as the idiomatic guide on how to get all pages for a given resource (a common use case without an obvious solution, hence the docs can be very helpful). --- github/doc.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/github/doc.go b/github/doc.go index d723e0e..8dee026 100644 --- a/github/doc.go +++ b/github/doc.go @@ -95,5 +95,31 @@ bool, and int values. For example: client.Repositories.Create("", repo) Users who have worked with protocol buffers should find this pattern familiar. + +Pagination + +All requests for resource collections (repos, pull requests, issues, etc) +support pagination. Pagination options are described in the +ListOptions struct and passed to the list methods directly or as an +embedded type of a more specific list options struct (for example +PullRequestListOptions). Pages information is available via Response struct. + + opt := &github.RepositoryListByOrgOptions{ + ListOptions: github.ListOptions{PerPage: 10}, + } + // get all pages of results + var allRepos []github.Repository + for { + repos, resp, err := client.Repositories.ListByOrg("github", opt) + if err != nil { + return err + } + allRepos = append(allRepos, repos...) + if resp.NextPage == 0 { + break + } + opt.ListOptions.Page = resp.NextPage + } + */ package github