Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xrstf/pager

Simple Pager for Go
https://github.com/xrstf/pager

Last synced: 17 days ago
JSON representation

Simple Pager for Go

Awesome Lists containing this project

README

        

Go Pager
========

This package implements a very basic pager, useful for creating paginations on lists in various
applications. The pager automatically inserts ``…`` in the sequence of links to prevent excessive
amounts of links being generated.

There is no output logic implemented here. You put in a few basic numbers and get back a list of
abstract ``Link`` structures. Rendering those is your task.

Examples
--------

```go
import "github.com/xrstf/pager"

currentPage := 0 // pages start at zero
elementsPerPage := 10
totalElements := 1234

// a basic pager sets a few sane default values;
// use pager.NewPager() to control all of them
myPager := pager.NewBasicPager(currentPage, totalElements, elementsPerPage)

// links is a []pager.Link slice
links := myPager.Links()

// render as you like
for _, link := links {
if link.Type == pager.LinkFirst {
writeSomewhere("<<")
} else if link.Type == pager.LinkPrev {
writeSomewhere("<")
}
// etc.
}
```

License
-------

The code is licensed under the MIT license.