Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PaginatorPageKey and PaginatorPerPageKey variables #615

Merged
merged 3 commits into from Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pagination_test.go
Expand Up @@ -31,12 +31,12 @@ func Test_NewPaginatorFromParams(t *testing.T) {
a.Equal(p.Page, 1)
a.Equal(p.PerPage, 20)

params.Set("page", "2")
params.Set(PaginatorPageKey, "2")
p = NewPaginatorFromParams(params)
a.Equal(p.Page, 2)
a.Equal(p.PerPage, 20)

params.Set("per_page", "30")
params.Set(PaginatorPerPageKey, "30")
p = NewPaginatorFromParams(params)
a.Equal(p.Page, 2)
a.Equal(p.PerPage, 30)
Expand Down
4 changes: 2 additions & 2 deletions paginator.go
Expand Up @@ -75,9 +75,9 @@ type PaginationParams interface {
// `PaginatorPerPageKey`. Defaults are `1` for the page and
// PaginatorPerPageDefault for the per page value.
func NewPaginatorFromParams(params PaginationParams) *Paginator {
page := defaults.String(params.Get("page"), "1")
page := defaults.String(params.Get(PaginatorPageKey), "1")

perPage := defaults.String(params.Get("per_page"), strconv.Itoa(PaginatorPerPageDefault))
perPage := defaults.String(params.Get(PaginatorPerPageKey), strconv.Itoa(PaginatorPerPageDefault))

p, err := strconv.Atoi(page)
if err != nil {
Expand Down