1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package sqs
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/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Returns a list of your queues in the current region. The response includes a
15// maximum of 1,000 results. If you specify a value for the optional
16// QueueNamePrefix parameter, only queues with a name that begins with the
17// specified value are returned. The listQueues methods supports pagination. Set
18// parameter MaxResults in the request to specify the maximum number of results to
19// be returned in the response. If you do not set MaxResults, the response includes
20// a maximum of 1,000 results. If you set MaxResults and there are additional
21// results to display, the response includes a value for NextToken. Use NextToken
22// as a parameter in your next request to listQueues to receive the next page of
23// results. Cross-account permissions don't apply to this action. For more
24// information, see Grant cross-account permissions to a role and a user name
25// (https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-customer-managed-policy-examples.html#grant-cross-account-permissions-to-role-and-user-name)
26// in the Amazon Simple Queue Service Developer Guide.
27func (c *Client) ListQueues(ctx context.Context, params *ListQueuesInput, optFns ...func(*Options)) (*ListQueuesOutput, error) {
28	if params == nil {
29		params = &ListQueuesInput{}
30	}
31
32	result, metadata, err := c.invokeOperation(ctx, "ListQueues", params, optFns, addOperationListQueuesMiddlewares)
33	if err != nil {
34		return nil, err
35	}
36
37	out := result.(*ListQueuesOutput)
38	out.ResultMetadata = metadata
39	return out, nil
40}
41
42//
43type ListQueuesInput struct {
44
45	// Maximum number of results to include in the response. Value range is 1 to 1000.
46	// You must set MaxResults to receive a value for NextToken in the response.
47	MaxResults *int32
48
49	// Pagination token to request the next set of results.
50	NextToken *string
51
52	// A string to use for filtering the list results. Only those queues whose name
53	// begins with the specified string are returned. Queue URLs and names are
54	// case-sensitive.
55	QueueNamePrefix *string
56}
57
58// A list of your queues.
59type ListQueuesOutput struct {
60
61	// Pagination token to include in the next request. Token value is null if there
62	// are no additional results to request, or if you did not set MaxResults in the
63	// request.
64	NextToken *string
65
66	// A list of queue URLs, up to 1,000 entries, or the value of MaxResults that you
67	// sent in the request.
68	QueueUrls []string
69
70	// Metadata pertaining to the operation's result.
71	ResultMetadata middleware.Metadata
72}
73
74func addOperationListQueuesMiddlewares(stack *middleware.Stack, options Options) (err error) {
75	err = stack.Serialize.Add(&awsAwsquery_serializeOpListQueues{}, middleware.After)
76	if err != nil {
77		return err
78	}
79	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpListQueues{}, middleware.After)
80	if err != nil {
81		return err
82	}
83	if err = addSetLoggerMiddleware(stack, options); err != nil {
84		return err
85	}
86	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
87		return err
88	}
89	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
90		return err
91	}
92	if err = addResolveEndpointMiddleware(stack, options); err != nil {
93		return err
94	}
95	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
96		return err
97	}
98	if err = addRetryMiddlewares(stack, options); err != nil {
99		return err
100	}
101	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
102		return err
103	}
104	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
105		return err
106	}
107	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
108		return err
109	}
110	if err = addClientUserAgent(stack); err != nil {
111		return err
112	}
113	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
114		return err
115	}
116	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
117		return err
118	}
119	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListQueues(options.Region), middleware.Before); err != nil {
120		return err
121	}
122	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
123		return err
124	}
125	if err = addResponseErrorMiddleware(stack); err != nil {
126		return err
127	}
128	if err = addRequestResponseLogging(stack, options); err != nil {
129		return err
130	}
131	return nil
132}
133
134// ListQueuesAPIClient is a client that implements the ListQueues operation.
135type ListQueuesAPIClient interface {
136	ListQueues(context.Context, *ListQueuesInput, ...func(*Options)) (*ListQueuesOutput, error)
137}
138
139var _ ListQueuesAPIClient = (*Client)(nil)
140
141// ListQueuesPaginatorOptions is the paginator options for ListQueues
142type ListQueuesPaginatorOptions struct {
143	// Maximum number of results to include in the response. Value range is 1 to 1000.
144	// You must set MaxResults to receive a value for NextToken in the response.
145	Limit int32
146
147	// Set to true if pagination should stop if the service returns a pagination token
148	// that matches the most recent token provided to the service.
149	StopOnDuplicateToken bool
150}
151
152// ListQueuesPaginator is a paginator for ListQueues
153type ListQueuesPaginator struct {
154	options   ListQueuesPaginatorOptions
155	client    ListQueuesAPIClient
156	params    *ListQueuesInput
157	nextToken *string
158	firstPage bool
159}
160
161// NewListQueuesPaginator returns a new ListQueuesPaginator
162func NewListQueuesPaginator(client ListQueuesAPIClient, params *ListQueuesInput, optFns ...func(*ListQueuesPaginatorOptions)) *ListQueuesPaginator {
163	options := ListQueuesPaginatorOptions{}
164	if params.MaxResults != nil {
165		options.Limit = *params.MaxResults
166	}
167
168	for _, fn := range optFns {
169		fn(&options)
170	}
171
172	if params == nil {
173		params = &ListQueuesInput{}
174	}
175
176	return &ListQueuesPaginator{
177		options:   options,
178		client:    client,
179		params:    params,
180		firstPage: true,
181	}
182}
183
184// HasMorePages returns a boolean indicating whether more pages are available
185func (p *ListQueuesPaginator) HasMorePages() bool {
186	return p.firstPage || p.nextToken != nil
187}
188
189// NextPage retrieves the next ListQueues page.
190func (p *ListQueuesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListQueuesOutput, error) {
191	if !p.HasMorePages() {
192		return nil, fmt.Errorf("no more pages available")
193	}
194
195	params := *p.params
196	params.NextToken = p.nextToken
197
198	var limit *int32
199	if p.options.Limit > 0 {
200		limit = &p.options.Limit
201	}
202	params.MaxResults = limit
203
204	result, err := p.client.ListQueues(ctx, &params, optFns...)
205	if err != nil {
206		return nil, err
207	}
208	p.firstPage = false
209
210	prevToken := p.nextToken
211	p.nextToken = result.NextToken
212
213	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
214		p.nextToken = nil
215	}
216
217	return result, nil
218}
219
220func newServiceMetadataMiddleware_opListQueues(region string) *awsmiddleware.RegisterServiceMetadata {
221	return &awsmiddleware.RegisterServiceMetadata{
222		Region:        region,
223		ServiceID:     ServiceID,
224		SigningName:   "sqs",
225		OperationName: "ListQueues",
226	}
227}
228