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