{"id":29659342,"url":"https://github.com/webstradev/gin-pagination","last_synced_at":"2025-07-22T09:10:46.715Z","repository":{"id":65134419,"uuid":"581654427","full_name":"webstradev/gin-pagination","owner":"webstradev","description":"Pagination middleware for the gin framework","archived":false,"fork":false,"pushed_at":"2025-04-17T10:41:15.000Z","size":104,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-18T01:26:09.061Z","etag":null,"topics":["gin","go","golang","middleware","pagination","web"],"latest_commit_sha":null,"homepage":"","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/webstradev.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-23T21:09:19.000Z","updated_at":"2025-04-17T20:27:21.000Z","dependencies_parsed_at":"2023-12-11T18:30:20.057Z","dependency_job_id":"c9783645-09c4-4ec9-8134-692635333d55","html_url":"https://github.com/webstradev/gin-pagination","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/webstradev/gin-pagination","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webstradev%2Fgin-pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webstradev%2Fgin-pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webstradev%2Fgin-pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webstradev%2Fgin-pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webstradev","download_url":"https://codeload.github.com/webstradev/gin-pagination/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webstradev%2Fgin-pagination/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266463569,"owners_count":23932904,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["gin","go","golang","middleware","pagination","web"],"created_at":"2025-07-22T09:10:45.796Z","updated_at":"2025-07-22T09:10:46.656Z","avatar_url":"https://github.com/webstradev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-pagination\n[![Run Tests](https://github.com/webstradev/gin-pagination/actions/workflows/test.yml/badge.svg)](https://github.com/webstradev/gin-pagination/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/webstradev/gin-pagination/branch/master/graph/badge.svg?token=C2D4QHYHI4)](https://codecov.io/gh/webstradev/gin-pagination)\n[![Go Reference](https://pkg.go.dev/badge/github.com/webstradev/gin-pagination.svg)](https://pkg.go.dev/github.com/webstradev/gin-pagination/v2)\n[![Go Report Card](https://goreportcard.com/badge/github.com/webstradev/gin-pagination/v2)](https://goreportcard.com/report/github.com/webstradev/gin-pagination/v2)\n[![CodeQL](https://github.com/webstradev/gin-pagination/actions/workflows/codeql.yml/badge.svg)](https://github.com/webstradev/gin-pagination/actions/workflows/codeql.yml)\n\nSimple pagination middleware for the gin framework. Allows for the usage of url parameters like `?page=1\u0026size=25` to paginate data on your API.\n\n## Installation\n```bash\n$ go get github.com/webstradev/gin-pagination/v2\n```\n\n## Default Usage\nThis package comes with a default pagination handler. This uses query parameters `page` and `size` with default values of `1` and `10` and a maximum page size of `100`.\n\n#### Using the middleware on a router will apply the it to all requests on that router:\n```go\npackage main\n\nimport (\n  \"net/http\"\n\n  \"github.com/gin-gonic/gin\"\n  \"github.com/webstradev/gin-pagination/v2/pkg/pagination\"\n)\n\nfunc main(){\n  r := gin.Default()\n  \n  r.Use(pagination.New())\n  \n  r.GET(\"/hello\", func(c *gin.Context){\n    c.Status(http.StatusOK)  \n  })\n  \n  r.Run(\":3000\")\n}\n```\n\n#### Using the middleware on a single route will only apply it to that route:\n```go\npackage main\n\nimport (\n  \"net/http\"\n  \n  \"github.com/gin-gonic/gin\"\n  \"github.com/webstradev/gin-pagination/v2/pkg/pagination\"\n)\n\nfunc main(){\n  r := gin.Default()\n  \n  r.GET(\"/hello\", pagination.New(), func(c *gin.Context){\n    page := c.GetInt(\"page\")\n  \n    c.JSON(http.StatusOK, gin.H{\"page\" : page})  \n  })\n  \n  r.Run(\":3000\")\n}\n```\nThe `page` and `size` are now available in the gin context of a request and can be used to paginate your data (for example in an SQL query).\n\n \n## Custom Usage\nTo create a pagination middleware with custom parameters the New() function supports various custom options provided as functions that overwrite the default value.\nAll the options can be seen in the example below.\n```go\npackage main\n\nimport (\n  \"net/http\"\n  \n  \"github.com/gin-gonic/gin\"\n  \"github.com/webstradev/gin-pagination/v2/pkg/pagination\"\n)\n\nfunc main(){\n  r := gin.Default()\n  \n  paginator := pagination.New(\n    pagination.WithPageText(\"page\"), \n    pagination.WithSizeText(\"rowsPerPage\"),\n    pagination.WithDefaultPage(1),\n    pagination.WithDefaultPageSize(15),\n    pagination.WithMinPageSize(5),\n    pagination.WithMaxPageSize(15),\n    pagination.WithHeaderPrefix(\"\"),\n  )\n  \n  r.GET(\"/hello\", paginator, func(c *gin.Context){\n    c.Status(http.StatusOK)  \n  })\n  \n  r.Run(\":3000\")\n}\n```\n\nThe custom middleware can also be used on an entire router object similarly to the first example fo the Default Usage.\n\n## Similar package\nI've written a similar package for the labstack echo framework called [echo-pagination](https://github.com/webstradev/echo-pagination)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebstradev%2Fgin-pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebstradev%2Fgin-pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebstradev%2Fgin-pagination/lists"}