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