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.
Hi. I frequently use this library in my projects. When working with list operations, I'm writing a lot of similar code, like this:
In one project, I created pagination util to refactor such code into:
The source code is available here: https://github.com/g4s8/gitstrap/blob/master/internal/gitstrap/pagination.go
This util automatically update
ListOptionsnext page from accumulatedResponsepage properties, and returntrueif next page exist to use it inforloop.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.