{"id":21823685,"url":"https://github.com/godcong/paginator","last_synced_at":"2025-03-21T11:42:28.873Z","repository":{"id":57568939,"uuid":"343623873","full_name":"godcong/paginator","owner":"godcong","description":"Paginator for go web developers","archived":false,"fork":false,"pushed_at":"2024-03-29T19:34:32.000Z","size":64,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T08:11:23.629Z","etag":null,"topics":["go","page","pagination","paginator","web"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/godcong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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":"2021-03-02T02:41:40.000Z","updated_at":"2022-11-07T10:57:25.000Z","dependencies_parsed_at":"2024-06-20T01:40:04.370Z","dependency_job_id":"7f45ef04-2c70-41a5-a852-1649116e3746","html_url":"https://github.com/godcong/paginator","commit_stats":{"total_commits":49,"total_committers":1,"mean_commits":49.0,"dds":0.0,"last_synced_commit":"723722c17b175a6db8f6962dd181fcdca128c0b1"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godcong%2Fpaginator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godcong%2Fpaginator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godcong%2Fpaginator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godcong%2Fpaginator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/godcong","download_url":"https://codeload.github.com/godcong/paginator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244794872,"owners_count":20511516,"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","page","pagination","paginator","web"],"created_at":"2024-11-27T17:36:03.865Z","updated_at":"2025-03-21T11:42:28.829Z","avatar_url":"https://github.com/godcong.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# paginator\n\n## Paginator is a go-based page-turning extension package\n\n## Usage\n\n- Create the paginator object\n\n```go\npackage example\n\nimport \"github.com/godcong/paginator/v3\"\n\nfunc main() {\n\tp := paginator.New() //create the paginator module for use\n\t//you can create a paginator with a custom options\n\tp := paginator.New(paginator.PerPageOption(30))           //paging 30 items per page\n\tp := paginator.New(paginator.PerPageKeyOption(\"perPage\")) //set per page key with option\n\tp := paginator.New(paginator.PageKeyOption(\"page\"))       //set page key with option\n\tp := paginator.New(paginator.PerPageOption(30),\n\t\tpaginator.PerPageKeyOption(\"perPage\"), paginator.PageKeyOption(\"page\")) //create the paginator module with all custom options\n\n\t//use the paginator\n\tpage, err := p.Parse(Queryable) //parse will return the current page data and error \n}\n\n```\n\n- Implement the Queryable interface\n\n```\n//Turnable at least 3 interfaces that need to be implemented\nQueryable //return the Finder for paginator query\n\nCounter //count the total data\nGetter  //find the data by page\n//optional\nCloner //all the data \n```\n\n- A Queryable example\n\n```go\npackage example\n\nimport (\n\t\"context\"\n\n\t\"github.com/godcong/paginator/v3\"\n)\n\ntype pageExample struct {\n\tquery *Query\n}\n\nfunc (p pageExample) Count(ctx context.Context) (int64, error) {\n\tcount, err := p.query.Count(ctx)\n\treturn int64(count), err\n}\n\nfunc (p pageExample) Clone() paginator.Finder {\n\treturn p.query.Clone()\n}\n\nfunc (p pageExample) Finder(parser paginator.Parser) paginator.Finder {\n\tv := parser.FindValue(\"catch\", \"\")\n\tif v != \"\" {\n\t\tp.query = p.query.Where(Cacth(v))\n\t}\n\tid := parser.FindValue(\"id\", \"\")\n\tif id != \"\" {\n\t\tp.query = p.query.Where(page.IDEq(id))\n\t}\n\n\treturn p\n}\n\nfunc main() {\n\t//then use\n\tp.SetDefaultQuery(\u0026pageExample{})\n\tpage, err := p.Parse(paginator.NewHTTPParser(req))\n\t//or\n\tpage, err := p.ParseWithQuery(paginator.NewHTTPParser(req), \u0026pageExample)\n}\n```\n\n- Request from web\n\n```\n   http://127.0.0.1/api/v0/example?per_page=20\u0026page=xx\u0026id=xx,\n```\n\nresult will like this:\n\n```json\n{\n  \"current_page\": 1,\n  \"last_page\": 1,\n  \"per_page\": 20,\n  \"data\": [\n    {\n      \"id\": \"1\",\n      \"name\": \"test1\"\n    },\n    {\n      \"id\": \"2\",\n      \"name\": \"test2\"\n    }\n  ],\n  \"total\": 2,\n  \"first_page_url\": \"127.0.0.1/api/v0/example?page=1\u0026per_page=20\",\n  \"last_page_url\": \"127.0.0.1/api/v0/example?page=1\u0026per_page=20\",\n  \"next_page_url\": \"\",\n  \"prev_page_url\": \"\",\n  \"path\": \"127.0.0.1/api/v0/example\"\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgodcong%2Fpaginator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgodcong%2Fpaginator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgodcong%2Fpaginator/lists"}