{"id":21447859,"url":"https://github.com/hsbc/go-api-pagination","last_synced_at":"2025-07-14T20:30:54.014Z","repository":{"id":188008396,"uuid":"677942912","full_name":"hsbc/go-api-pagination","owner":"hsbc","description":"A pagination provider for the go-github golang module","archived":false,"fork":false,"pushed_at":"2024-11-01T01:24:31.000Z","size":502,"stargazers_count":5,"open_issues_count":4,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-01T02:22:11.666Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hsbc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-08-13T06:47:28.000Z","updated_at":"2024-11-01T01:23:34.000Z","dependencies_parsed_at":"2023-11-12T14:25:28.018Z","dependency_job_id":"afac6e0c-75a7-43f3-ba19-4e9177d7b01c","html_url":"https://github.com/hsbc/go-api-pagination","commit_stats":null,"previous_names":["xorima/go-github-pagination","xorima/go-api-pagination","hsbc/go-api-pagination"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsbc%2Fgo-api-pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsbc%2Fgo-api-pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsbc%2Fgo-api-pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsbc%2Fgo-api-pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hsbc","download_url":"https://codeload.github.com/hsbc/go-api-pagination/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225994783,"owners_count":17556830,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T03:12:26.130Z","updated_at":"2024-11-23T03:12:26.738Z","avatar_url":"https://github.com/hsbc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-api-pagination\n\n## Introduction\n\nThe `pagination` package provides a simple and efficient way to handle pagination with the GitHub API. It offers interfaces and functions to list, process, and handle rate limits for any type of items you wish to paginate through.\n\n## Getting Started\n\n### Installation\n\nTo get started with the `pagination` package, you can install it using the `go get` command:\n\n```bash\ngo get github.com/hsbc/go-api-pagination\n```\n\n### Importing the Package\n\nAfter installation, you can import the package in your Go code:\n\n```go\nimport \"github.com/hsbc/go-api-pagination/pagination\"\n```\n\n## Usage\n\n### Interfaces\n\n1. **ListFunc**: This interface returns a list of items for the given type. It requires the implementation of the `List` method which fetches the items.\n\n2. **ProcessFunc**: This interface processes an item for the given type. It requires the implementation of the `Process` method which processes each item.\n\n3. **RateLimitFunc**: This interface handles rate limiting. It requires the implementation of the `RateLimit` method which decides whether to continue pagination based on rate limits.\n\n### Paginator Function\n\nThe main function provided by this package is `Paginator`. It takes in the following parameters:\n\n- `ctx`: The context for the API calls.\n- `listFunc`: An instance of a type that implements the `ListFunc` interface.\n- `processFunc`: An instance of a type that implements the `ProcessFunc` interface.\n- `rateLimitFunc`: An instance of a type that implements the `RateLimitFunc` interface.\n- `Opts`: An instance of `PaginatorOpts` which contains list options like `PerPage` and `Page`.\n\nThe function paginates through the items, processes them, handles rate limits, and returns all the items.\n\n### Example Implementations\n\nHere are example implementations for the interfaces:\n\n```go\ntype listFunc struct {\n\tclient *github.Client\n}\n\nfunc (l *listFunc) List(ctx context.Context, opt *github.ListOptions) ([]*github.Repository, *github.Response, error) {\n\tt, r, err := l.client.Apps.ListRepos(ctx, opt)\n\treturn t.Repositories, r, err\n}\n\ntype processFunc struct {\n\tclient *github.Client\n}\n\nfunc (p *processFunc) Process(ctx context.Context, item *github.Repository) error {\n\tfmt.Println(item.GetName())\n\treturn nil\n}\n\ntype rateLimitFunc struct {\n}\n\nfunc (r *rateLimitFunc) RateLimit(ctx context.Context, resp *github.Response) (bool, error) {\n\tif resp.Rate.Remaining \u003c= 1 {\n\t\ttime.Sleep(time.Until(resp.Rate.Reset.Time))\n\t}\n\treturn true, nil\n}\n```\n\n### Using the Paginator Function with Example Implementations\n\n```go\n// Initialize the GitHub client\ngithubClient := github.NewClient(nil)\n\n// Define your list, process, and rate limit functions\nlistFuncInstance := \u0026listFunc{client: githubClient}\nprocessFuncInstance := \u0026processFunc{client: githubClient}\nrateLimitFuncInstance := \u0026rateLimitFunc{}\n\n// Call the Paginator function\nitems, err := pagination.Paginator(ctx, listFuncInstance, processFuncInstance, rateLimitFuncInstance, \u0026pagination.PaginatorOpts{\n    ListOptions: \u0026github.ListOptions{PerPage: 50, Page: 1},\n})\nif err != nil {\n    log.Fatalf(\"Error paginating: %v\", err)\n}\n\n// Process the items\nfor _, item := range items {\n    // Your logic here\n}\n```\n\n## Conclusion\n\nThe `pagination` package simplifies the process of paginating through items from the GitHub API. By providing clear interfaces, example implementations, and a main Paginator function, it abstracts away the complexities of pagination, rate limiting, and item processing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsbc%2Fgo-api-pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhsbc%2Fgo-api-pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsbc%2Fgo-api-pagination/lists"}