Skip to content

Commit

Permalink
Merge pull request #3 from statsbomb/add_pagination
Browse files Browse the repository at this point in the history
Add pagination to ListNodes API call
  • Loading branch information
joshm91 authored May 7, 2021
2 parents e0c7c2e + 5a170c8 commit bd8c5ac
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,go
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,go

### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,go

msk_file_sd.yml
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 bd8c5ac

Please sign in to comment.