Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crufter/paging
A simple paging script written in Go, for use with template engines like mustache, or the builting template package of Go.
https://github.com/crufter/paging
Last synced: about 1 month ago
JSON representation
A simple paging script written in Go, for use with template engines like mustache, or the builting template package of Go.
- Host: GitHub
- URL: https://github.com/crufter/paging
- Owner: crufter
- Created: 2012-05-28T13:26:44.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-07-28T11:49:15.000Z (over 12 years ago)
- Last Synced: 2024-11-30T21:48:46.640Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 109 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Paging
======A simple paging script written in Go, for use with template engines like mustache, or the builting template package of Go.
Usage
======
The Paging(current_page, page_count, visible int, url_str string) function will return a []paging.Pelem.
The visible parameter controls how many paging "link" can be seen before and after the current page.
The first and the last page will be always in the list.
```
package mainimport(
"github.com/opesun/paging"
)func main() {
x, _ := paging.P(1, 5, 2, "http://www.opesun.com?cat=embedded")
paging.Print(x)
fmt.Println("---")
paging.PrintWithUrl(x)
}
```The above example will output
```
[1] 2 3 ... 5
---
[1] http://www.opesun.com?cat=embedded&page=1
2 http://www.opesun.com?cat=embedded&page=2
3 http://www.opesun.com?cat=embedded&page=3
...
5 http://www.opesun.com?cat=embedded&page=5
```Unfortunately the get parameters will be ordered randomly in the url since the net/url package url.Value type does not keep the order of the parameters, since it uses
a map internally.