Browse Source

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).
Dmitri Shuralyov 12 years ago
committed by Will Norris
parent
commit
fab0662d46
1 changed files with 26 additions and 0 deletions
  1. +26
    -0
      github/doc.go

+ 26
- 0
github/doc.go View File

@ -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

Loading…
Cancel
Save