{"id":18716587,"url":"https://github.com/timothyye/martini-paginate","last_synced_at":"2025-07-04T22:36:02.042Z","repository":{"id":57541998,"uuid":"24455158","full_name":"TimothyYe/martini-paginate","owner":"TimothyYe","description":"A pagination plugin for go-martini web framework.","archived":false,"fork":false,"pushed_at":"2015-06-05T09:05:26.000Z","size":164,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-28T10:30:20.523Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimothyYe.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}},"created_at":"2014-09-25T11:19:15.000Z","updated_at":"2015-07-06T06:24:30.000Z","dependencies_parsed_at":"2022-09-08T23:32:09.145Z","dependency_job_id":null,"html_url":"https://github.com/TimothyYe/martini-paginate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyYe%2Fmartini-paginate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyYe%2Fmartini-paginate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyYe%2Fmartini-paginate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyYe%2Fmartini-paginate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimothyYe","download_url":"https://codeload.github.com/TimothyYe/martini-paginate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239581802,"owners_count":19662958,"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-07T13:13:09.494Z","updated_at":"2025-02-19T01:41:38.309Z","avatar_url":"https://github.com/TimothyYe.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"martini-paginate\n================\n\nA pagination plugin for go-martini web framework.\n\n## Installation\n\nImport it into source code:\n\n```go\nimport (\n\t\"github.com/timothyye/martini-paginate\"\n)\n```\n\nThen get package and source code:\n\n```bash\ngo get\n```\n\n## Usage\n\n* Set paginator's handler as the middleware:\n\n```go\nm = martini.Classic()\nm.Get(\"/casts\", paginate.Handler, HandleCasts)\n```\n\n* In handler function, initialize the paginator with page size and record total amount:\n\n```go\nfunc HandleCasts(r render.Render, db *mgo.Database, pager *paginate.Paginator) {\n\tnum, _ := db.C(\"casts\").Count()\n\n\tpers := 6\n\tpager.Init(pers, num)\n\n\tcasts := []models.Casts{}\n\t\n\tdb.C(\"casts\").Find(nil).Limit(pers).Skip(pager.Offset()).All(\u0026casts)\n\n\tr.HTML(200, \"casts\", map[string]interface{}{\n\t\t\"IsCasts\":   true,\n\t\t\"Casts\":     casts,\n\t\t\"Paginator\": pager,\n\t\t\"Num\":       num})\n}\n```\n\n* In template, visit the paginator and render the page:\n\n```html\n\u003cdiv class=\"m-b-xl\"\u003e\n\t{{if gt .Paginator.PageNums 1}}\n\t\u003cul class=\"pagination pagination-sm\"\u003e\n\t\t{{if .Paginator.HasPrev}}\n\t\t\t\u003cli\u003e\u003ca href=\"{{.Paginator.PageLinkFirst}}\"\u003eFirst\u003c/a\u003e\u003c/li\u003e\n\t\t\t\u003cli\u003e\u003ca href=\"{{.Paginator.PageLinkPrev}}\"\u003e\u0026lt;\u003c/a\u003e\u003c/li\u003e\n\t\t{{else}}\n\t\t\t\u003cli class=\"disabled\"\u003e\u003ca\u003eFirst\u003c/a\u003e\u003c/li\u003e\n\t\t\t\u003cli class=\"disabled\"\u003e\u003ca\u003e\u0026lt;\u003c/a\u003e\u003c/li\u003e\n\t\t{{end}}\n\t\t\n\t\t{{range $index, $page := .Paginator.Pages}}\n\t\t\t\u003cli{{if $.Paginator.IsActive .}} class=\"active\"{{end}}\u003e\n\t\t\t\t\u003ca href=\"{{$.Paginator.PageLink $page}}\"\u003e{{$page}}\u003c/a\u003e\n\t\t\t\u003c/li\u003e\n\t\t{{end}}\n\t\t{{if .Paginator.HasNext}}\n\t\t\t\u003cli\u003e\u003ca href=\"{{.Paginator.PageLinkNext}}\"\u003e\u0026gt;\u003c/a\u003e\u003c/li\u003e\n\t\t\t\u003cli\u003e\u003ca href=\"{{.Paginator.PageLinkLast}}\"\u003eLast\u003c/a\u003e\u003c/li\u003e\n\t\t{{else}}\n\t\t\t\u003cli class=\"disabled\"\u003e\u003ca\u003e\u0026gt;\u003c/a\u003e\u003c/li\u003e\n\t\t\t\u003cli class=\"disabled\"\u003e\u003ca\u003eLast\u003c/a\u003e\u003c/li\u003e\n\t\t{{end}}\n\t\u003c/ul\u003e\n\t{{end}}\n\u003c/div\u003e\n```\n\n## More examples\n\nFor more examples, please refer to the source code of [Vim-Tips.com](https://github.com/TimothyYe/vim-tips-web)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothyye%2Fmartini-paginate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimothyye%2Fmartini-paginate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothyye%2Fmartini-paginate/lists"}