Skip to content

Conversation

@francesconi
Copy link
Member

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

@francesconi francesconi self-assigned this Aug 23, 2024
@francesconi francesconi added the enhancement New feature or request label Aug 23, 2024
Option[T any] func(*Paginator[T])
)

func New[T any](page, pageSize int, opts ...Option[T]) Paginator[T] {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally would reduce the default page sitze to 50.
Auth0 does this.

image


func Parse[T any](r *http.Request, opts ...Option[T]) Paginator[T] {
q := r.URL.Query()
page, _ := strconv.Atoi(q.Get("page"))
Copy link
Member

@davidspiess davidspiess Dec 3, 2024

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"`
Copy link
Member

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.

@davidspiess davidspiess self-requested a review January 2, 2025 11:25
@francesconi francesconi merged commit 9ca6d2f into main Jan 2, 2025
1 check passed
@francesconi francesconi deleted the offset-pagination branch January 2, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants