Total Pageviews

Saturday, 13 August 2016


Simple pagination for go, with HTML support.
 Coverage Godoc license
Pagination is a simple package that provides pagination. Has HTML support using the html/template package.


Install using go get.
$ go get
Then import it in your project.
import ""


Create a basic pagination and check the offset for current page
numPosts := db.Posts().Count()
postsPerPage := 25
currentPage := request.Query().Int("page")
p := pagination.New(numPosts, postsPerPage, currentPage)
fmt.Printf("The current offset is: %d\n", p.Offset()) // The current offset is: 75
Create a HTML pagination and use it in a html/template
p := pagination.NewHTML(110, 25, 2)
data := map[string]interface{}{
  "Pager": p,
var out bytes.Buffer
t := template.Must(template.New("pagination-test").Parse("{{ .Pager.Render }}"))
t.Execute(&out, data)
fmt.Printf("HTML list: %s\n", out.String())


Run the tests using go test.
$ go test