File: handwritten_paginators.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.30.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 662,428 kB
  • sloc: java: 16,875; makefile: 432; sh: 175
file content (113 lines) | stat: -rw-r--r-- 3,548 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package route53

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/route53/types"
)

// ListResourceRecordSetsAPIClient is a client that implements the ListResourceRecordSets
// operation
type ListResourceRecordSetsAPIClient interface {
	ListResourceRecordSets(context.Context, *ListResourceRecordSetsInput, ...func(*Options)) (*ListResourceRecordSetsOutput, error)
}

var _ ListResourceRecordSetsAPIClient = (*Client)(nil)

// ListResourceRecordSetsPaginatorOptions is the paginator options for ListResourceRecordSets
type ListResourceRecordSetsPaginatorOptions struct {
	// (Optional) The maximum number of ResourceRecordSets that you want Amazon Route 53 to
	// return.
	Limit int32

	// Set to true if pagination should stop if the service returns a pagination token
	// that matches the most recent token provided to the service.
	StopOnDuplicateToken bool
}

// ListResourceRecordSetsPaginator is a paginator for ListResourceRecordSets
type ListResourceRecordSetsPaginator struct {
	options               ListResourceRecordSetsPaginatorOptions
	client                ListResourceRecordSetsAPIClient
	params                *ListResourceRecordSetsInput
	firstPage             bool
	startRecordName       *string
	startRecordType       types.RRType
	startRecordIdentifier *string
	isTruncated           bool
}

// NewListResourceRecordSetsPaginator returns a new ListResourceRecordSetsPaginator
func NewListResourceRecordSetsPaginator(client ListResourceRecordSetsAPIClient, params *ListResourceRecordSetsInput, optFns ...func(*ListResourceRecordSetsPaginatorOptions)) *ListResourceRecordSetsPaginator {
	if params == nil {
		params = &ListResourceRecordSetsInput{}
	}

	options := ListResourceRecordSetsPaginatorOptions{}
	if params.MaxItems != nil {
		options.Limit = *params.MaxItems
	}

	for _, fn := range optFns {
		fn(&options)
	}

	return &ListResourceRecordSetsPaginator{
		options:               options,
		client:                client,
		params:                params,
		firstPage:             true,
		startRecordName:       params.StartRecordName,
		startRecordType:       params.StartRecordType,
		startRecordIdentifier: params.StartRecordIdentifier,
	}
}

// HasMorePages returns a boolean indicating whether more pages are available
func (p *ListResourceRecordSetsPaginator) HasMorePages() bool {
	return p.firstPage || p.isTruncated
}

// NextPage retrieves the next ListResourceRecordSets page.
func (p *ListResourceRecordSetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListResourceRecordSetsOutput, error) {
	if !p.HasMorePages() {
		return nil, fmt.Errorf("no more pages available")
	}

	params := *p.params
	params.StartRecordName = p.startRecordName
	params.StartRecordIdentifier = p.startRecordIdentifier
	params.StartRecordType = p.startRecordType

	var limit *int32
	if p.options.Limit > 0 {
		limit = &p.options.Limit
	}
	params.MaxItems = limit

	result, err := p.client.ListResourceRecordSets(ctx, &params, optFns...)
	if err != nil {
		return nil, err
	}
	p.firstPage = false

	prevToken := p.startRecordName
	p.isTruncated = result.IsTruncated
	p.startRecordName = nil
	p.startRecordIdentifier = nil
	p.startRecordType = ""
	if result.IsTruncated {
		p.startRecordName = result.NextRecordName
		p.startRecordIdentifier = result.NextRecordIdentifier
		p.startRecordType = result.NextRecordType
	}

	if p.options.StopOnDuplicateToken &&
		prevToken != nil &&
		p.startRecordName != nil &&
		*prevToken == *p.startRecordName {
		p.isTruncated = false
	}

	return result, nil
}