Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/xrstf/pager
- Owner: xrstf
- Created: 2015-09-06T21:23:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-06T21:59:20.000Z (over 9 years ago)
- Last Synced: 2024-12-17T13:52:28.466Z (22 days ago)
- Language: Go
- Size: 121 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.