-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Hi. I frequently use this library in my projects. When working with list operations, I'm writing a lot of similar code, like this:
opt := new(github.ListOptions)
for {
res, rsp, err := cli.SomeListOperations(args, opts)
// handle error
if rsp.NextPage == 0 {
break
}
// process rsp
opts.Page = rsp.NextPage
}In one project, I created pagination util to refactor such code into:
opt := new(github.ListOptions)
pagination := new(pagination)
for pagination.moveNext(opts) {
res, rsp, err := cli.SomeListOperations(args, opts)
// handle error
pagination.update(rsp)
// process rsp
}The source code is available here: https://github.com/g4s8/gitstrap/blob/master/internal/gitstrap/pagination.go
This util automatically update ListOptions next page from accumulated Response page properties, and return true if next page exist to use it in for loop.
I think that such kind of tool is more convenient than manual operations on response and page options, what do you think? If you agree, I'm ready to submit a PR.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels