Add pagination helper to easily collect all items #1498
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚧 THIS IS MERELY AN EXPERIMENT FOR NOW! 🚧
The #1496 Pull Request triggered
some thinking for how to do this in a more "generic" way.
Thus, I drafted this
gitlab.Collect()
function, which can be used to"easily" collect all items of a specific "list" API (I've implement a
collect function which eagerly collects all items, but something
similar can be implemented for channels to stream).
The only downside of the current implementation so far is that Go
doesn't really support generics / interfaces with direct field access as
of now ... effectively, you'll always need methods.
This means that, because the
ListOptions
field is somewhatinconsistently (sometimes as subfield, sometimes it's promoted)
implemented over this package every
gitlab.List*Options
struct needsit's own
GetPage() int
andSetPage(int)
implementation ...One improvement for this could be that we split out the
ListOptions
from the API endpoint specific options and make it an additional
argument to the list methods - so that
Collect()
could profit fromthis and
GetPage() int
andSetPage(int)
would only need to beimplemented once.
Another one would be to just use
gitlab.ListOptions
for endpointswhich don't have additional parameters instead of doing this
type ListInstanceVariablesOptions ListOptions
.However, I think best would be to separate the generic
ListOptions
toa separate argument in the long term ...
@svanharmelen what do you think?