2022-05-19 15:24:26 +02:00
|
|
|
package pagination
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Pagination struct {
|
2022-06-16 11:27:18 +02:00
|
|
|
PerPage int
|
|
|
|
Cursor int
|
|
|
|
Next bool
|
|
|
|
FirstPage bool
|
2022-05-19 15:24:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetPagination(q url.Values) Pagination {
|
|
|
|
var (
|
2022-06-16 11:27:18 +02:00
|
|
|
pp, _ = strconv.Atoi(q.Get("per_page"))
|
|
|
|
cursor, _ = strconv.Atoi(q.Get("cursor"))
|
|
|
|
next, _ = strconv.ParseBool(q.Get("next"))
|
|
|
|
firstPage = false
|
2022-05-19 15:24:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if pp > 100 {
|
|
|
|
pp = 100
|
|
|
|
}
|
|
|
|
|
2022-06-16 11:27:18 +02:00
|
|
|
if !next && cursor < 1 {
|
|
|
|
firstPage = true
|
2022-05-19 15:24:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Pagination{
|
2022-06-16 11:27:18 +02:00
|
|
|
PerPage: pp,
|
|
|
|
Cursor: cursor,
|
|
|
|
Next: next,
|
|
|
|
FirstPage: firstPage,
|
2022-05-19 15:24:26 +02:00
|
|
|
}
|
|
|
|
}
|