handwritten_paginators.go raw
1 package route53
2
3 import (
4 "context"
5 "fmt"
6 "github.com/aws/aws-sdk-go-v2/service/route53/types"
7 )
8
9 // ListResourceRecordSetsAPIClient is a client that implements the ListResourceRecordSets
10 // operation
11 type ListResourceRecordSetsAPIClient interface {
12 ListResourceRecordSets(context.Context, *ListResourceRecordSetsInput, ...func(*Options)) (*ListResourceRecordSetsOutput, error)
13 }
14
15 var _ ListResourceRecordSetsAPIClient = (*Client)(nil)
16
17 // ListResourceRecordSetsPaginatorOptions is the paginator options for ListResourceRecordSets
18 type ListResourceRecordSetsPaginatorOptions struct {
19 // (Optional) The maximum number of ResourceRecordSets that you want Amazon Route 53 to
20 // return.
21 Limit int32
22
23 // Set to true if pagination should stop if the service returns a pagination token
24 // that matches the most recent token provided to the service.
25 StopOnDuplicateToken bool
26 }
27
28 // ListResourceRecordSetsPaginator is a paginator for ListResourceRecordSets
29 type ListResourceRecordSetsPaginator struct {
30 options ListResourceRecordSetsPaginatorOptions
31 client ListResourceRecordSetsAPIClient
32 params *ListResourceRecordSetsInput
33 firstPage bool
34 startRecordName *string
35 startRecordType types.RRType
36 startRecordIdentifier *string
37 isTruncated bool
38 }
39
40 // NewListResourceRecordSetsPaginator returns a new ListResourceRecordSetsPaginator
41 func NewListResourceRecordSetsPaginator(client ListResourceRecordSetsAPIClient, params *ListResourceRecordSetsInput, optFns ...func(*ListResourceRecordSetsPaginatorOptions)) *ListResourceRecordSetsPaginator {
42 if params == nil {
43 params = &ListResourceRecordSetsInput{}
44 }
45
46 options := ListResourceRecordSetsPaginatorOptions{}
47 if params.MaxItems != nil {
48 options.Limit = *params.MaxItems
49 }
50
51 for _, fn := range optFns {
52 fn(&options)
53 }
54
55 return &ListResourceRecordSetsPaginator{
56 options: options,
57 client: client,
58 params: params,
59 firstPage: true,
60 startRecordName: params.StartRecordName,
61 startRecordType: params.StartRecordType,
62 startRecordIdentifier: params.StartRecordIdentifier,
63 }
64 }
65
66 // HasMorePages returns a boolean indicating whether more pages are available
67 func (p *ListResourceRecordSetsPaginator) HasMorePages() bool {
68 return p.firstPage || p.isTruncated
69 }
70
71 // NextPage retrieves the next ListResourceRecordSets page.
72 func (p *ListResourceRecordSetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListResourceRecordSetsOutput, error) {
73 if !p.HasMorePages() {
74 return nil, fmt.Errorf("no more pages available")
75 }
76
77 params := *p.params
78 params.StartRecordName = p.startRecordName
79 params.StartRecordIdentifier = p.startRecordIdentifier
80 params.StartRecordType = p.startRecordType
81
82 var limit *int32
83 if p.options.Limit > 0 {
84 limit = &p.options.Limit
85 }
86 params.MaxItems = limit
87
88 result, err := p.client.ListResourceRecordSets(ctx, ¶ms, optFns...)
89 if err != nil {
90 return nil, err
91 }
92 p.firstPage = false
93
94 prevToken := p.startRecordName
95 p.isTruncated = result.IsTruncated
96 p.startRecordName = nil
97 p.startRecordIdentifier = nil
98 p.startRecordType = ""
99 if result.IsTruncated {
100 p.startRecordName = result.NextRecordName
101 p.startRecordIdentifier = result.NextRecordIdentifier
102 p.startRecordType = result.NextRecordType
103 }
104
105 if p.options.StopOnDuplicateToken &&
106 prevToken != nil &&
107 p.startRecordName != nil &&
108 *prevToken == *p.startRecordName {
109 p.isTruncated = false
110 }
111
112 return result, nil
113 }
114