A pagination plugin for go-martini web framework.

## Installation

Import it into source code:

import (

Then get package and source code:

go get

## Usage

* Set paginator's handler as the middleware:

m = martini.Classic()
m.Get("/casts", paginate.Handler, HandleCasts)

* In handler function, initialize the paginator with page size and record total amount:

func HandleCasts(r render.Render, db *mgo.Database, pager *paginate.Paginator) {
	num, _ := db.C("casts").Count()

	pers := 6
	pager.Init(pers, num)

	casts := []models.Casts{}

	r.HTML(200, "casts", map[string]interface{}{
		"IsCasts":   true,
		"Casts":     casts,
		"Paginator": pager,
		"Num":       num})

* In template, visit the paginator and render the page:

<div class="m-b-xl">
	{{if gt .Paginator.PageNums 1}}
	<ul class="pagination pagination-sm">
		{{if .Paginator.HasPrev}}
			<li><a href="{{.Paginator.PageLinkFirst}}">First</a></li>
			<li><a href="{{.Paginator.PageLinkPrev}}">&lt;</a></li>
			<li class="disabled"><a>First</a></li>
			<li class="disabled"><a>&lt;</a></li>
		{{range $index, $page := .Paginator.Pages}}
			<li{{if $.Paginator.IsActive .}} class="active"{{end}}>
				<a href="{{$.Paginator.PageLink $page}}">{{$page}}</a>
		{{if .Paginator.HasNext}}
			<li><a href="{{.Paginator.PageLinkNext}}">&gt;</a></li>
			<li><a href="{{.Paginator.PageLinkLast}}">Last</a></li>
			<li class="disabled"><a>&gt;</a></li>
			<li class="disabled"><a>Last</a></li>

## More examples

For more examples, please refer to the source code of [](

Imports 1 package(s) ΒΆ