api_op_ListCidrCollections.go (5488B)
1 // Code generated by smithy-go-codegen DO NOT EDIT. 2 3 package route53 4 5 import ( 6 "context" 7 "fmt" 8 9 "github.com/aws/aws-sdk-go-v2/service/route53/types" 10 "github.com/aws/smithy-go/middleware" 11 ) 12 13 // Returns a paginated list of CIDR collections in the Amazon Web Services account 14 // (metadata only). 15 func (c *Client) ListCidrCollections(ctx context.Context, params *ListCidrCollectionsInput, optFns ...func(*Options)) (*ListCidrCollectionsOutput, error) { 16 if params == nil { 17 params = &ListCidrCollectionsInput{} 18 } 19 20 result, metadata, err := c.invokeOperation(ctx, "ListCidrCollections", params, optFns, c.addOperationListCidrCollectionsMiddlewares) 21 if err != nil { 22 return nil, err 23 } 24 25 out := result.(*ListCidrCollectionsOutput) 26 out.ResultMetadata = metadata 27 return out, nil 28 } 29 30 type ListCidrCollectionsInput struct { 31 32 // The maximum number of CIDR collections to return in the response. 33 MaxResults *int32 34 35 // An opaque pagination token to indicate where the service is to begin 36 // enumerating results. 37 // 38 // If no value is provided, the listing of results starts from the beginning. 39 NextToken *string 40 41 noSmithyDocumentSerde 42 } 43 44 type ListCidrCollectionsOutput struct { 45 46 // A complex type with information about the CIDR collection. 47 CidrCollections []types.CollectionSummary 48 49 // An opaque pagination token to indicate where the service is to begin 50 // enumerating results. 51 // 52 // If no value is provided, the listing of results starts from the beginning. 53 NextToken *string 54 55 // Metadata pertaining to the operation's result. 56 ResultMetadata middleware.Metadata 57 58 noSmithyDocumentSerde 59 } 60 61 func (c *Client) addOperationListCidrCollectionsMiddlewares(stack *middleware.Stack, options Options) (err error) { 62 err = stack.Serialize.Add(&awsRestxml_serializeOpListCidrCollections{}, middleware.After) 63 if err != nil { 64 return err 65 } 66 err = stack.Deserialize.Add(&awsRestxml_deserializeOpListCidrCollections{}, middleware.After) 67 if err != nil { 68 return err 69 } 70 71 if err = addComputeContentLength(stack); err != nil { 72 return err 73 } 74 if err = addResolveEndpointMiddleware(stack, options); err != nil { 75 return err 76 } 77 if err = addComputePayloadSHA256(stack); err != nil { 78 return err 79 } 80 if err = addRecordResponseTiming(stack, options); err != nil { 81 return err 82 } 83 if err = addCredentialSource(stack, options); err != nil { 84 return err 85 } 86 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 87 return err 88 } 89 if err = addResponseErrorMiddleware(stack); err != nil { 90 return err 91 } 92 if err = addRequestResponseLogging(stack, options); err != nil { 93 return err 94 } 95 if err = addDisableHTTPSMiddleware(stack, options); err != nil { 96 return err 97 } 98 if err = addInterceptors(stack, options); err != nil { 99 return err 100 } 101 return nil 102 } 103 104 // ListCidrCollectionsPaginatorOptions is the paginator options for 105 // ListCidrCollections 106 type ListCidrCollectionsPaginatorOptions struct { 107 // The maximum number of CIDR collections to return in the response. 108 Limit int32 109 110 // Set to true if pagination should stop if the service returns a pagination token 111 // that matches the most recent token provided to the service. 112 StopOnDuplicateToken bool 113 } 114 115 // ListCidrCollectionsPaginator is a paginator for ListCidrCollections 116 type ListCidrCollectionsPaginator struct { 117 options ListCidrCollectionsPaginatorOptions 118 client ListCidrCollectionsAPIClient 119 params *ListCidrCollectionsInput 120 nextToken *string 121 firstPage bool 122 } 123 124 // NewListCidrCollectionsPaginator returns a new ListCidrCollectionsPaginator 125 func NewListCidrCollectionsPaginator(client ListCidrCollectionsAPIClient, params *ListCidrCollectionsInput, optFns ...func(*ListCidrCollectionsPaginatorOptions)) *ListCidrCollectionsPaginator { 126 if params == nil { 127 params = &ListCidrCollectionsInput{} 128 } 129 130 options := ListCidrCollectionsPaginatorOptions{} 131 if params.MaxResults != nil { 132 options.Limit = *params.MaxResults 133 } 134 135 for _, fn := range optFns { 136 fn(&options) 137 } 138 139 return &ListCidrCollectionsPaginator{ 140 options: options, 141 client: client, 142 params: params, 143 firstPage: true, 144 nextToken: params.NextToken, 145 } 146 } 147 148 // HasMorePages returns a boolean indicating whether more pages are available 149 func (p *ListCidrCollectionsPaginator) HasMorePages() bool { 150 return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0) 151 } 152 153 // NextPage retrieves the next ListCidrCollections page. 154 func (p *ListCidrCollectionsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListCidrCollectionsOutput, error) { 155 if !p.HasMorePages() { 156 return nil, fmt.Errorf("no more pages available") 157 } 158 159 params := *p.params 160 params.NextToken = p.nextToken 161 162 var limit *int32 163 if p.options.Limit > 0 { 164 limit = &p.options.Limit 165 } 166 params.MaxResults = limit 167 168 optFns = append([]func(*Options){ 169 addIsPaginatorUserAgent, 170 }, optFns...) 171 result, err := p.client.ListCidrCollections(ctx, ¶ms, optFns...) 172 if err != nil { 173 return nil, err 174 } 175 p.firstPage = false 176 177 prevToken := p.nextToken 178 p.nextToken = result.NextToken 179 180 if p.options.StopOnDuplicateToken && 181 prevToken != nil && 182 p.nextToken != nil && 183 *prevToken == *p.nextToken { 184 p.nextToken = nil 185 } 186 187 return result, nil 188 } 189 190 // ListCidrCollectionsAPIClient is a client that implements the 191 // ListCidrCollections operation. 192 type ListCidrCollectionsAPIClient interface { 193 ListCidrCollections(context.Context, *ListCidrCollectionsInput, ...func(*Options)) (*ListCidrCollectionsOutput, error) 194 } 195 196 var _ ListCidrCollectionsAPIClient = (*Client)(nil)