{"id":17435748,"url":"https://github.com/nejdetkadir/pagygo","last_synced_at":"2025-03-28T01:21:34.783Z","repository":{"id":257809170,"uuid":"867272823","full_name":"nejdetkadir/pagygo","owner":"nejdetkadir","description":"A flexible pagination library for Golang","archived":false,"fork":false,"pushed_at":"2024-10-03T18:53:38.000Z","size":144,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T03:17:42.261Z","etag":null,"topics":["go","go-lib","go-library","go-pagination","golang","pagination","pagination-library","paging","paging-library"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nejdetkadir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-03T18:48:39.000Z","updated_at":"2024-10-03T18:50:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"fe8e927c-3cbe-4176-b412-14da725a50fa","html_url":"https://github.com/nejdetkadir/pagygo","commit_stats":null,"previous_names":["nejdetkadir/pagygo"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nejdetkadir%2Fpagygo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nejdetkadir%2Fpagygo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nejdetkadir%2Fpagygo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nejdetkadir%2Fpagygo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nejdetkadir","download_url":"https://codeload.github.com/nejdetkadir/pagygo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245950514,"owners_count":20699085,"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":["go","go-lib","go-library","go-pagination","golang","pagination","pagination-library","paging","paging-library"],"created_at":"2024-10-17T10:01:11.479Z","updated_at":"2025-03-28T01:21:34.764Z","avatar_url":"https://github.com/nejdetkadir.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build and test](https://github.com/nejdetkadir/pagygo/actions/workflows/main.yml/badge.svg?branch=main)\n![Go Version](https://img.shields.io/badge/go_version-_1.23.1-007d9c.svg)\n\n![cover](docs/cover.png)\n\n# Pagygo\n\nPagygo is a flexible pagination library for Golang, designed to handle large or irregular datasets. It supports advanced features such as dynamic filtering, custom sorting, and configurable pagination options to suit a variety of use cases.\n\n## Features\n- **Dynamic Filtering:** Filter data based on custom logic before paginating.\n- **Custom Sorting:** Define sorting logic using a callback function.\n- **Pagination Controls:** Configure the number of items per page and navigate between pages.\n- **Thread-Safe Operations:** All operations are safe to use in concurrent environments.\n- **Meta Information:** Get detailed pagination metadata like current page, total pages, and more.\n\n## Installation\nTo install Pagygo, use the following command:\n\n```bash\ngo get github.com/nejdetkadir/pagygo\n```\n\n## Usage\n### Initialize Pagygo\nCreate a new instance of the pagination context and configure the items to paginate, along with custom options if needed.\n\n```go\npackage main\n\nimport (\n    \"github.com/nejdetkadir/pagygo\"\n    \"fmt\"\n)\n\nfunc main() {\n    items := []interface{}{1, 2, 3, 4, 5}\n    config := pagygo.Config{}\n\n    paginator := pagygo.New(items, config)\n    result := paginator.Paginate()\n\n    fmt.Printf(\"Current Page: %d, Total Items: %d\\n\", result.Meta.CurrentPage, result.Meta.TotalItemsCount)\n}\n```\n\n### Customize Pagination\nYou can specify the current page and the number of items per page.\n\n```go\nresult := paginator.Page(2).PerPage(10).Paginate()\n```\n\n### Filtering Items\nUse the FilterBy function to define a filtering logic for the items.\n\n```go\nresult := paginator.FilterBy(func(item interface{}) bool {\n    return item.(int) % 2 == 0\n}).Paginate()\n\nfmt.Println(result.Items) // Output: [2 4]\n```\n\n### Sorting Items\nYou can pass a custom sorting function to order the items before pagination.\n\n```go\nresult := paginator.OrderBy(func(items []interface{}) []interface{} {\n    // Reverse the items\n    for i := len(items)/2 - 1; i \u003e= 0; i-- {\n        opp := len(items) - 1 - i\n        items[i], items[opp] = items[opp], items[i]\n    }\n    return items\n}).Paginate()\n\nfmt.Println(result.Items) // Output: [5 4 3 2 1]\n```\n\n### Pagination Metadata\nAfter calling Paginate(), you will receive detailed pagination metadata in the Meta struct. The fields include:\n\n- **CurrentPage:** The current page number.\n- **PrevPage:** The previous page number (or nil if there is no previous page).\n- **NextPage:** The next page number (or nil if there is no next page).\n- **PerPage:** The number of items per page.\n- **TotalPagesCount:** The total number of pages based on the items and PerPage setting.\n- **TotalItemsCount:** The total number of items after filtering (if any filter is applied).\n- **IsFirstPage:** A boolean indicating whether the current page is the first page.\n- **IsLastPage**: A boolean indicating whether the current page is the last page.\n\nHere is an example of how to access the metadata:\n\n```go\nmeta := result.Meta\nfmt.Printf(\n    \"Current Page: %d\\nTotal Pages: %d\\nTotal Items: %d\\nIs First Page: %v\\nIs Last Page: %v\\nPrev Page: %v\\nNext Page: %v\\nItems Per Page: %d\\n\",\n    meta.CurrentPage,        // Current page number\n    meta.TotalPagesCount,    // Total pages available\n    meta.TotalItemsCount,    // Total number of items\n    meta.IsFirstPage,        // Is this the first page?\n    meta.IsLastPage,         // Is this the last page?\n    meta.PrevPage,           // Previous page number (nil if no previous page)\n    meta.NextPage,           // Next page number (nil if no next page)\n    meta.PerPage,            // Number of items per page\n)\n```\n\nFor example, the output might look like this:\n\n```\nCurrent Page: 1\nTotal Pages: 3\nTotal Items: 50\nIs First Page: true\nIs Last Page: false\nPrev Page: \u003cnil\u003e\nNext Page: 2\nItems Per Page: 20\n```\n\n### Example with All Features\n```go\nresult := paginator.Page(2).PerPage(5).\n    FilterBy(func(item interface{}) bool { return item.(int) \u003e 2 }).\n    OrderBy(func(items []interface{}) []interface{} { \n        // Example sorting logic\n        return items \n    }).Paginate()\n\nfmt.Println(result.Items) // Paginated, filtered, and sorted items\n```\n\n## Example\nCheck out the [example](example/main.go) for a complete demonstration of pagygo usage.\n\n## Unit Testing\nThe package includes comprehensive unit tests to ensure correct behavior across various scenarios. To run the tests, use the following:\n\n```b![cover.png](../../../Downloads/cover.png)ash\ngo test ./...\n```\n\n## Contributing\nBug reports and pull requests are welcome on GitHub at https://github.com/nejdetkadir/pagygo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nejdetkadir/pagygo/blob/main/CODE_OF_CONDUCT.md).\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnejdetkadir%2Fpagygo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnejdetkadir%2Fpagygo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnejdetkadir%2Fpagygo/lists"}