Giter VIP home page Giter VIP logo

go-github-pagination's Introduction

go-github-pagination

Go Report Card

Package go-github-pagination provides an http.RoundTripper implementation that handles Pagination for the GitHub API.
go-github-pagination can be used with any HTTP client communicating with GitHub API.
It is meant to complement go-github, but this repository is not associated with go-github repository nor Google.

Installation

go get github.com/gofri/go-github-pagination

Usage Example (with go-github)

import "github.com/google/go-github/v58/github"
import "github.com/gofri/go-github-pagination/github_pagination"

func main() {
  paginator, err := github_pagination.NewGithubPaginationClient(nil)
  if err != nil {
    panic(err)
  }
  client := github.NewClient(paginator).WithAuthToken("your personal access token")

  // now use the client as you please
}

Known Limitations

All of these may be developed in the future (some are definitly on the roadmap).
Please open an issue or a pull request if you need any.
Unsupported features (at this point):

  • Async interface (see below).
  • Total pages limitation.
  • Custom strategy in case of primary/secondary rate limits / errors.
  • Per-request configuration override.
  • Concurrent fetching of pages.
  • Progress bar styled report (callback).
  • Reverse pagination (does that really make sense to anyone?)
  • GraphQL pagination.

Async Pagination

Async pagination refers to handling pages while fetching the next pages.
Unfortunately, the interfaces of both http.Client & go_github.Client have a sync nature.
This fact makes total sense for itself, but it makes it impossible to shove async pagination under the hood without abusing the interface.
As a result, async pagination must be supported via an additional interface. Although not yet implemented, it is likely to be something like ch := PaginateAsync(request_action, args...). Specifically, I intend to provide an interface that accepts go-github functions for usability. Please feel free to share you thoughts/needs for this interface.

Incomplete Results

According to the (obscure) API documentation, some endpoints may return a dictionary instead of an array. This return scheme is used to report incomplete results (due to timeouts).

The result is expected to be of the following structure (the actual items dictionary differs per endpoint):

{
  "total_count": 0,
  "incomplete_results": false,
  "items": [{}]
}

The merge strategy used is to summarize the total_count, OR the incomplete_results, and join the items. In practice, this special case appears to only occur with the Search API.
Please report incidents with a different behaviour if you face them.

Internals - How Does It Work?

The implementation consists of a few building blocks:

  • json_merger: merges the response body (slice/map) of the pages.
  • pagination_utils: utilities to handle the pagination API used by GitHub.
  • github_pagination: the main package that glues everything into an http.RoundTripper.

GitHub Pagination API Documentation References

License

This package is distributed under the MIT license found in the LICENSE file.
Contribution and feedback is welcome.

go-github-pagination's People

Contributors

gofri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.