-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
018632e
commit 373d2bb
Showing
5 changed files
with
46 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
package pagination | ||
|
||
const defaultPageSize = 20 | ||
const defaultPerPage = 20 | ||
|
||
type Request struct { | ||
Page int // page requested (default 1) | ||
PageSize int // Number of items per page | ||
Page int // page requested (default 1) | ||
PerPage int // Number of items per page | ||
} | ||
|
||
func NewRequest(page, pageSize int) Request { | ||
func NewRequest(page, perPage int) Request { | ||
if page < 1 { | ||
page = 1 | ||
} | ||
if pageSize < 1 { | ||
pageSize = defaultPageSize | ||
if perPage < 1 { | ||
perPage = defaultPerPage | ||
} | ||
return Request{ | ||
Page: page, | ||
PageSize: pageSize, | ||
Page: page, | ||
PerPage: perPage, | ||
} | ||
} | ||
|
||
func (p Request) Limit() int { | ||
return p.PageSize | ||
return p.PerPage | ||
} | ||
|
||
func (p Request) Offset() int { | ||
return (p.Page - 1) * p.PageSize | ||
return (p.Page - 1) * p.PerPage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters