![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)
Pagination is a simple package that provides pagination. Has HTML support using the html/template
package.
Installation
Install using go get
.
$ go get github.com/SayonAB/pagination
Then import it in your project.
import "github.com/SayonAB/pagination"
Usage
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())
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())
Testing
Run the tests using go test
.
$ go test
Contributing
All contributions are welcome! See CONTRIBUTING for more info.
License
Licensed under MIT license. See LICENSE for more information.