Skip to content

Commit aa58bd8

Browse files
chore: refactor list params to include 'limit' (#101)
1 parent f103905 commit aa58bd8

File tree

559 files changed

+3651
-1680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

559 files changed

+3651
-1680
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,14 @@ func main() {
328328
params := &openapi.ListMessageParams{}
329329
params.SetFrom(from)
330330
params.SetPageSize(20)
331-
limit := 100
331+
params.SetLimit(100)
332332

333-
resp, _ := client.ApiV2010.ListMessage(params, limit)
333+
resp, _ := client.ApiV2010.ListMessage(params)
334334
for record := range resp {
335335
fmt.Println("Body: ", *resp[record].Body)
336336
}
337337

338-
channel, _ := client.ApiV2010.StreamMessage(params, limit)
338+
channel, _ := client.ApiV2010.StreamMessage(params)
339339
for record := range channel {
340340
fmt.Println("Body: ", *record.Body)
341341
}

client/page_util.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ import (
1010
)
1111

1212
//Takes a limit on the max number of records to read and a max pageSize and calculates the max number of pages to read.
13-
func ReadLimits(pageSize *int, limit int) int {
13+
func ReadLimits(pageSize *int, limit *int) int {
1414
//don't care about pageSize
1515
if pageSize == nil {
16-
if limit == 0 {
16+
if limit == nil {
1717
//don't care about the limit either
1818
return 50 //default
1919
}
2020
//return the most efficient pageSize
21-
return min(limit, 1000)
21+
return min(*limit, 1000)
2222
} else {
23-
if limit == 0 {
23+
if limit == nil {
2424
//we care about the pageSize but not the limit
2525
return *pageSize
2626
}
27-
return min(*pageSize, limit)
27+
return min(*pageSize, *limit)
2828
}
2929
}
3030

31-
func GetNext(response interface{}, curRecord *int, limit int, getNextPage func(nextPageUri string) (interface{}, error)) (interface{}, error) {
31+
func GetNext(response interface{}, curRecord *int, limit *int, getNextPage func(nextPageUri string) (interface{}, error)) (interface{}, error) {
3232
nextPageUri, err := getNextPageUri(response, curRecord, limit)
3333
if err != nil {
3434
return nil, err
@@ -72,7 +72,7 @@ func toMap(s interface{}) map[string]interface{} {
7272
return payload
7373
}
7474

75-
func getNextPageUri(response interface{}, curRecord *int, limit int) (string, error) {
75+
func getNextPageUri(response interface{}, curRecord *int, limit *int) (string, error) {
7676
//get just the non metadata info and the next page uri
7777
payload, nextPageUri, err := GetPayload(response)
7878
if err != nil {
@@ -81,13 +81,13 @@ func getNextPageUri(response interface{}, curRecord *int, limit int) (string, er
8181

8282
*curRecord += len(payload)
8383

84-
if limit != 0 {
84+
if limit != nil {
8585
//we have reached the desired limit
86-
if limit <= *curRecord {
86+
if *limit <= *curRecord {
8787
return "", nil
8888
}
8989

90-
remaining := limit - *curRecord
90+
remaining := *limit - *curRecord
9191
if remaining > 0 {
9292
pageSize := min(len(payload), remaining)
9393
re := regexp.MustCompile(`PageSize=\d+`)

client/page_util_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import (
77
)
88

99
func TestReadLimits(t *testing.T) {
10-
assert.Equal(t, 5, ReadLimits(nil, 5))
11-
assert.Equal(t, 5, ReadLimits(setPageSize(10), 5))
12-
assert.Equal(t, 1000, ReadLimits(nil, 5000))
13-
assert.Equal(t, 10, ReadLimits(setPageSize(10), 0))
14-
assert.Equal(t, 50, ReadLimits(nil, 0))
10+
assert.Equal(t, 5, ReadLimits(nil, setLimit(5)))
11+
assert.Equal(t, 5, ReadLimits(setPageSize(10), setLimit(5)))
12+
assert.Equal(t, 1000, ReadLimits(nil, setLimit(5000)))
13+
assert.Equal(t, 10, ReadLimits(setPageSize(10), nil))
14+
assert.Equal(t, 50, ReadLimits(nil, nil))
15+
}
16+
17+
func setLimit(limit int) *int {
18+
return &limit
1519
}
1620

1721
func setPageSize(pageSize int) *int {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ require (
88
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
99
github.com/pkg/errors v0.9.1
1010
github.com/stretchr/testify v1.7.0
11+
golang.org/x/tools v0.1.5 // indirect
1112
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
1213
)

go.sum

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
1515
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1616
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1717
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18+
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
19+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
20+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
21+
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
22+
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
23+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
24+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
25+
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
26+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
27+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
28+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
29+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
30+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
31+
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
32+
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
33+
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
34+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
35+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
36+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
37+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
38+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
39+
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
40+
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
41+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
42+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
43+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
44+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1845
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1946
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
2047
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

rest/accounts/v1/credentials_aws.go

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest/accounts/v1/credentials_public_keys.go

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest/accounts/v1/docs/CredentialsAWSApi.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Other parameters are passed through a pointer to a ListCredentialAwsParams struc
157157
Name | Type | Description
158158
------------- | ------------- | -------------
159159
**PageSize** | **int** | How many resources to return in each list page. The default is 50, and the maximum is 1000.
160+
**Limit** | **int** | Max number of records to return.
160161

161162
### Return type
162163

rest/accounts/v1/docs/CredentialsPublicKeysApi.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Other parameters are passed through a pointer to a ListCredentialPublicKeyParams
157157
Name | Type | Description
158158
------------- | ------------- | -------------
159159
**PageSize** | **int** | How many resources to return in each list page. The default is 50, and the maximum is 1000.
160+
**Limit** | **int** | Max number of records to return.
160161

161162
### Return type
162163

rest/api/v2010/accounts.go

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)