mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2024-12-22 19:07:33 +01:00
Mohammed Sohail
37538c68ff
- see docs for pagination api usage - added control for syncer/api goroutines
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,
|
|
}
|
|
}
|