Skip to content

Commit

Permalink
Chore: use generics in pagination (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Jun 12, 2022
1 parent 35aedc4 commit ec1993b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ jobs:
integration-tests:
name: Integration Tests
runs-on: ubuntu-20.04
container: hashicorp/terraform:1.1.6
container: golang:1.18-alpine3.16
timeout-minutes: 20
steps:
- name: Install Go
run: apk add go
- name: Install Terraform
run: apk add terraform
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run Harness tests
run: go run tests/harness.go
17 changes: 5 additions & 12 deletions client/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ type Pagination struct {
params map[string]string
}

// Note: all the FIXME should be uncommented when Alpine adds support for go 1.18.
// This will enable generics.

type Paginated interface {
// FIXME: Environment
Environment
getEndpoint() string
}

Expand All @@ -31,27 +28,23 @@ func (p *Pagination) next(currentPageSize int) bool {
}

// params - additional params. may be nil.
// FIXME: func getAll[P Paginated](client *ApiClient, params map[string]string) ([]P, error) {
func getAll(client *ApiClient, params map[string]string) ([]Environment, error) {
func getAll[P Paginated](client *ApiClient, params map[string]string) ([]P, error) {
p := Pagination{
offset: 0,
params: params,
}

// FIXME: var allResults []P
var allResults []Environment
var allResults []P

for {
pageParams := p.getParams()
for k, v := range params {
pageParams[k] = v
}

// FIXME: var pageResults []P
var pageResults []Environment
var pageResults []P

// FIXME: err := client.http.Get(P{}.getEndpoint(), pageParams, &pageResults)
err := client.http.Get(Environment{}.getEndpoint(), pageParams, &pageResults)
err := client.http.Get(P{}.getEndpoint(), pageParams, &pageResults)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ec1993b

Please sign in to comment.