@@ -23,7 +23,8 @@ type PageOptions struct {
2323// ListOptions are the pagination and filtering (TODO) parameters for endpoints
2424type ListOptions struct {
2525 * PageOptions
26- Filter string
26+ PageSize int
27+ Filter string
2728}
2829
2930// NewListOptions simplified construction of ListOptions using only
@@ -32,28 +33,38 @@ func NewListOptions(page int, filter string) *ListOptions {
3233 return & ListOptions {PageOptions : & PageOptions {Page : page }, Filter : filter }
3334}
3435
36+ func applyListOptionsToRequest (opts * ListOptions , req * resty.Request ) {
37+ if opts != nil {
38+ if opts .PageOptions != nil && opts .Page > 0 {
39+ req .SetQueryParam ("page" , strconv .Itoa (opts .Page ))
40+ }
41+
42+ if opts .PageSize > 0 {
43+ req .SetQueryParam ("page_size" , strconv .Itoa (opts .PageSize ))
44+ }
45+
46+ if len (opts .Filter ) > 0 {
47+ req .SetHeader ("X-Filter" , opts .Filter )
48+ }
49+ }
50+ }
51+
3552// listHelper abstracts fetching and pagination for GET endpoints that
3653// do not require any Ids (top level endpoints).
3754// When opts (or opts.Page) is nil, all pages will be fetched and
3855// returned in a single (endpoint-specific)PagedResponse
3956// opts.results and opts.pages will be updated from the API response
4057// nolint
4158func (c * Client ) listHelper (ctx context.Context , i interface {}, opts * ListOptions ) error {
42- req := c .R (ctx )
43- if opts != nil && opts .PageOptions != nil && opts .Page > 0 {
44- req .SetQueryParam ("page" , strconv .Itoa (opts .Page ))
45- }
46-
4759 var (
4860 err error
4961 pages int
5062 results int
5163 r * resty.Response
5264 )
5365
54- if opts != nil && len (opts .Filter ) > 0 {
55- req .SetHeader ("X-Filter" , opts .Filter )
56- }
66+ req := c .R (ctx )
67+ applyListOptionsToRequest (opts , req )
5768
5869 switch v := i .(type ) {
5970 case * LinodeKernelsPagedResponse :
@@ -295,23 +306,17 @@ func (c *Client) listHelper(ctx context.Context, i interface{}, opts *ListOption
295306// opts.results and opts.pages will be updated from the API response
296307// nolint
297308func (c * Client ) listHelperWithID (ctx context.Context , i interface {}, idRaw interface {}, opts * ListOptions ) error {
298- req := c .R (ctx )
299- if opts != nil && opts .Page > 0 {
300- req .SetQueryParam ("page" , strconv .Itoa (opts .Page ))
301- }
302-
303309 var (
304310 err error
305311 pages int
306312 results int
307313 r * resty.Response
308314 )
309315
310- id , _ := idRaw .(int )
316+ req := c .R (ctx )
317+ applyListOptionsToRequest (opts , req )
311318
312- if opts != nil && len (opts .Filter ) > 0 {
313- req .SetHeader ("X-Filter" , opts .Filter )
314- }
319+ id , _ := idRaw .(int )
315320
316321 switch v := i .(type ) {
317322 case * DomainRecordsPagedResponse :
@@ -436,23 +441,17 @@ func (c *Client) listHelperWithID(ctx context.Context, i interface{}, idRaw inte
436441// When opts (or opts.Page) is nil, all pages will be fetched and
437442// returned in a single (endpoint-specific)PagedResponse
438443// opts.results and opts.pages will be updated from the API response
444+ // nolint
439445func (c * Client ) listHelperWithTwoIDs (ctx context.Context , i interface {}, firstID , secondID int , opts * ListOptions ) error {
440- req := c .R (ctx )
441-
442- if opts != nil && opts .Page > 0 {
443- req .SetQueryParam ("page" , strconv .Itoa (opts .Page ))
444- }
445-
446446 var (
447447 err error
448448 pages int
449449 results int
450450 r * resty.Response
451451 )
452452
453- if opts != nil && len (opts .Filter ) > 0 {
454- req .SetHeader ("X-Filter" , opts .Filter )
455- }
453+ req := c .R (ctx )
454+ applyListOptionsToRequest (opts , req )
456455
457456 switch v := i .(type ) {
458457 case * NodeBalancerNodesPagedResponse :
0 commit comments