mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2024-11-14 03:46:46 +01:00
35 lines
477 B
Go
35 lines
477 B
Go
|
package pagination
|
||
|
|
||
|
import (
|
||
|
"net/url"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
type Pagination struct {
|
||
|
PerPage int
|
||
|
Cursor int
|
||
|
Forward bool
|
||
|
}
|
||
|
|
||
|
func GetPagination(q url.Values) Pagination {
|
||
|
var (
|
||
|
pp, _ = strconv.Atoi(q.Get("per_page"))
|
||
|
cursor, _ = strconv.Atoi(q.Get("cursor"))
|
||
|
forward, _ = strconv.ParseBool(q.Get("forward"))
|
||
|
)
|
||
|
|
||
|
if pp > 100 {
|
||
|
pp = 100
|
||
|
}
|
||
|
|
||
|
if !forward && cursor < 1 {
|
||
|
cursor = 1
|
||
|
}
|
||
|
|
||
|
return Pagination{
|
||
|
PerPage: pp,
|
||
|
Cursor: cursor,
|
||
|
Forward: forward,
|
||
|
}
|
||
|
}
|