spread icon indicating copy to clipboard operation
spread copied to clipboard

google: add generic pagination support on GCE results

Open mvo5 opened this issue 4 years ago • 0 comments

This PR adds (magic) pagination support to google backend in the dofl() helper. This is done in the following way:

The gogle GCE rest API has a lot of calls that return json values with the following structure:

type fooList struct {
    Items         []Item
    NextPageToken string
}

Cf. https://www.googleapis.com/discovery/v1/apis/compute/v1/rest

In the google backend code of spread a rest call to GCE is typically run with "dofl(..., &result)" where result points to a struct that has "Items []Item" like data.

The generic support for pagination will inspects result struct and if it finds an "Items" field it will create a slice of this type and for each call append to this copy. It will also automatically read try to read the next-page-token and continue calling the function until the next-page-token becomes empty.

This is an alternative way to solve the issue that PR#69 tackles.

mvo5 avatar Sep 12 '19 14:09 mvo5