mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-17 00:36:09 +02:00
add paging support to GetAll (#1601)
* add paging support to GetAll * fix import
This commit is contained in:
parent
8ada0c51dd
commit
a41c37f9e0
9 changed files with 322 additions and 103 deletions
|
@ -1,7 +1,10 @@
|
|||
// Package databroker contains databroker protobuf definitions.
|
||||
package databroker
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetUserID gets the databroker user id from a provider user id.
|
||||
func GetUserID(provider, providerUserID string) string {
|
||||
|
@ -30,3 +33,28 @@ func ApplyOffsetAndLimit(all []*Record, offset, limit int) (records []*Record, t
|
|||
}
|
||||
return records, len(all)
|
||||
}
|
||||
|
||||
// GetAllPages calls GetAll for all pages of data.
|
||||
func GetAllPages(ctx context.Context, client DataBrokerServiceClient, in *GetAllRequest) (*GetAllResponse, error) {
|
||||
var res GetAllResponse
|
||||
var pageToken string
|
||||
for {
|
||||
nxt, err := client.GetAll(ctx, &GetAllRequest{
|
||||
Type: in.GetType(),
|
||||
PageToken: pageToken,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res.ServerVersion = nxt.ServerVersion
|
||||
res.RecordVersion = nxt.RecordVersion
|
||||
res.Records = append(res.Records, nxt.Records...)
|
||||
|
||||
if nxt.NextPageToken == "" {
|
||||
break
|
||||
}
|
||||
pageToken = nxt.NextPageToken
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue