Skip to content

Commit

Permalink
Add pagination to ListNodes call
Browse files Browse the repository at this point in the history
  • Loading branch information
joshm91 committed May 7, 2021
1 parent f7de639 commit 5a170c8
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,20 @@ func getClusters(svc kafkaClient) (*kafka.ListClustersOutput, error) {
// getBrokers returns a slice of broker hosts without ports
func getBrokers(svc kafkaClient, arn string) ([]string, error) {
input := kafka.ListNodesInput{ClusterArn: &arn}
r, err := svc.ListNodes(context.Background(), &input)
var brokers []string

if err != nil {
return nil, err
}
p := kafka.NewListNodesPaginator(svc, &input)
for p.HasMorePages() {
page, err := p.NextPage(context.Background())
if err != nil {
return nil, err
}

var brokers []string
for _, b := range r.NodeInfoList {
brokers = append(brokers, b.BrokerNodeInfo.Endpoints...)
for _, b := range page.NodeInfoList {
brokers = append(brokers, b.BrokerNodeInfo.Endpoints...)
}
}

return brokers, nil
}

Expand Down

0 comments on commit 5a170c8

Please sign in to comment.