-
Notifications
You must be signed in to change notification settings - Fork 0
feat: offset pagination #1
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
Conversation
dc30438 to
b678269
Compare
| Option[T any] func(*Paginator[T]) | ||
| ) | ||
|
|
||
| func New[T any](page, pageSize int, opts ...Option[T]) Paginator[T] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would opt for passing the whole struct on initialisation, it's easy to missplace page and pageSize, which both are integers.
| ) | ||
|
|
||
| const ( | ||
| defaultPageSize int = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| func Parse[T any](r *http.Request, opts ...Option[T]) Paginator[T] { | ||
| q := r.URL.Query() | ||
| page, _ := strconv.Atoi(q.Get("page")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the approach of swallowing parsing errors
| } | ||
| Result[T any] struct { | ||
| Items []T `json:"items"` | ||
| NextPage *int `json:"next_page,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally would remove the pointer here, since omitempty works with default values too.
77e4971 to
1ad5f7f
Compare

Some guidelines were taken from https://google.aip.dev/158.