1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package mq 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/mq/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of all brokers. 16func (c *Client) ListBrokers(ctx context.Context, params *ListBrokersInput, optFns ...func(*Options)) (*ListBrokersOutput, error) { 17 if params == nil { 18 params = &ListBrokersInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListBrokers", params, optFns, c.addOperationListBrokersMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListBrokersOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListBrokersInput struct { 32 33 // The maximum number of brokers that Amazon MQ can return per page (20 by 34 // default). This value must be an integer from 5 to 100. 35 MaxResults int32 36 37 // The token that specifies the next page of results Amazon MQ should return. To 38 // request the first page, leave nextToken empty. 39 NextToken *string 40 41 noSmithyDocumentSerde 42} 43 44type ListBrokersOutput struct { 45 46 // A list of information about all brokers. 47 BrokerSummaries []types.BrokerSummary 48 49 // The token that specifies the next page of results Amazon MQ should return. To 50 // request the first page, leave nextToken empty. 51 NextToken *string 52 53 // Metadata pertaining to the operation's result. 54 ResultMetadata middleware.Metadata 55 56 noSmithyDocumentSerde 57} 58 59func (c *Client) addOperationListBrokersMiddlewares(stack *middleware.Stack, options Options) (err error) { 60 err = stack.Serialize.Add(&awsRestjson1_serializeOpListBrokers{}, middleware.After) 61 if err != nil { 62 return err 63 } 64 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListBrokers{}, middleware.After) 65 if err != nil { 66 return err 67 } 68 if err = addSetLoggerMiddleware(stack, options); err != nil { 69 return err 70 } 71 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 72 return err 73 } 74 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 75 return err 76 } 77 if err = addResolveEndpointMiddleware(stack, options); err != nil { 78 return err 79 } 80 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 81 return err 82 } 83 if err = addRetryMiddlewares(stack, options); err != nil { 84 return err 85 } 86 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 87 return err 88 } 89 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 90 return err 91 } 92 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 93 return err 94 } 95 if err = addClientUserAgent(stack); err != nil { 96 return err 97 } 98 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 99 return err 100 } 101 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 102 return err 103 } 104 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListBrokers(options.Region), middleware.Before); err != nil { 105 return err 106 } 107 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 108 return err 109 } 110 if err = addResponseErrorMiddleware(stack); err != nil { 111 return err 112 } 113 if err = addRequestResponseLogging(stack, options); err != nil { 114 return err 115 } 116 return nil 117} 118 119// ListBrokersAPIClient is a client that implements the ListBrokers operation. 120type ListBrokersAPIClient interface { 121 ListBrokers(context.Context, *ListBrokersInput, ...func(*Options)) (*ListBrokersOutput, error) 122} 123 124var _ ListBrokersAPIClient = (*Client)(nil) 125 126// ListBrokersPaginatorOptions is the paginator options for ListBrokers 127type ListBrokersPaginatorOptions struct { 128 // The maximum number of brokers that Amazon MQ can return per page (20 by 129 // default). This value must be an integer from 5 to 100. 130 Limit int32 131 132 // Set to true if pagination should stop if the service returns a pagination token 133 // that matches the most recent token provided to the service. 134 StopOnDuplicateToken bool 135} 136 137// ListBrokersPaginator is a paginator for ListBrokers 138type ListBrokersPaginator struct { 139 options ListBrokersPaginatorOptions 140 client ListBrokersAPIClient 141 params *ListBrokersInput 142 nextToken *string 143 firstPage bool 144} 145 146// NewListBrokersPaginator returns a new ListBrokersPaginator 147func NewListBrokersPaginator(client ListBrokersAPIClient, params *ListBrokersInput, optFns ...func(*ListBrokersPaginatorOptions)) *ListBrokersPaginator { 148 if params == nil { 149 params = &ListBrokersInput{} 150 } 151 152 options := ListBrokersPaginatorOptions{} 153 if params.MaxResults != 0 { 154 options.Limit = params.MaxResults 155 } 156 157 for _, fn := range optFns { 158 fn(&options) 159 } 160 161 return &ListBrokersPaginator{ 162 options: options, 163 client: client, 164 params: params, 165 firstPage: true, 166 } 167} 168 169// HasMorePages returns a boolean indicating whether more pages are available 170func (p *ListBrokersPaginator) HasMorePages() bool { 171 return p.firstPage || p.nextToken != nil 172} 173 174// NextPage retrieves the next ListBrokers page. 175func (p *ListBrokersPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListBrokersOutput, error) { 176 if !p.HasMorePages() { 177 return nil, fmt.Errorf("no more pages available") 178 } 179 180 params := *p.params 181 params.NextToken = p.nextToken 182 183 params.MaxResults = p.options.Limit 184 185 result, err := p.client.ListBrokers(ctx, ¶ms, optFns...) 186 if err != nil { 187 return nil, err 188 } 189 p.firstPage = false 190 191 prevToken := p.nextToken 192 p.nextToken = result.NextToken 193 194 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 195 p.nextToken = nil 196 } 197 198 return result, nil 199} 200 201func newServiceMetadataMiddleware_opListBrokers(region string) *awsmiddleware.RegisterServiceMetadata { 202 return &awsmiddleware.RegisterServiceMetadata{ 203 Region: region, 204 ServiceID: ServiceID, 205 SigningName: "mq", 206 OperationName: "ListBrokers", 207 } 208} 209