1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package rekognition
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 list of collection IDs in your account. If the result is truncated, the
15// response also provides a NextToken that you can use in the subsequent request to
16// fetch the next set of collection IDs. For an example, see Listing Collections in
17// the Amazon Rekognition Developer Guide. This operation requires permissions to
18// perform the rekognition:ListCollections action.
19func (c *Client) ListCollections(ctx context.Context, params *ListCollectionsInput, optFns ...func(*Options)) (*ListCollectionsOutput, error) {
20	if params == nil {
21		params = &ListCollectionsInput{}
22	}
23
24	result, metadata, err := c.invokeOperation(ctx, "ListCollections", params, optFns, addOperationListCollectionsMiddlewares)
25	if err != nil {
26		return nil, err
27	}
28
29	out := result.(*ListCollectionsOutput)
30	out.ResultMetadata = metadata
31	return out, nil
32}
33
34type ListCollectionsInput struct {
35
36	// Maximum number of collection IDs to return.
37	MaxResults *int32
38
39	// Pagination token from the previous response.
40	NextToken *string
41}
42
43type ListCollectionsOutput struct {
44
45	// An array of collection IDs.
46	CollectionIds []string
47
48	// Version numbers of the face detection models associated with the collections in
49	// the array CollectionIds. For example, the value of FaceModelVersions[2] is the
50	// version number for the face detection model used by the collection in
51	// CollectionId[2].
52	FaceModelVersions []string
53
54	// If the result is truncated, the response provides a NextToken that you can use
55	// in the subsequent request to fetch the next set of collection IDs.
56	NextToken *string
57
58	// Metadata pertaining to the operation's result.
59	ResultMetadata middleware.Metadata
60}
61
62func addOperationListCollectionsMiddlewares(stack *middleware.Stack, options Options) (err error) {
63	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListCollections{}, middleware.After)
64	if err != nil {
65		return err
66	}
67	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListCollections{}, middleware.After)
68	if err != nil {
69		return err
70	}
71	if err = addSetLoggerMiddleware(stack, options); err != nil {
72		return err
73	}
74	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
75		return err
76	}
77	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
78		return err
79	}
80	if err = addResolveEndpointMiddleware(stack, options); err != nil {
81		return err
82	}
83	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
84		return err
85	}
86	if err = addRetryMiddlewares(stack, options); err != nil {
87		return err
88	}
89	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
93		return err
94	}
95	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
96		return err
97	}
98	if err = addClientUserAgent(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
102		return err
103	}
104	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
105		return err
106	}
107	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListCollections(options.Region), middleware.Before); err != nil {
108		return err
109	}
110	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
111		return err
112	}
113	if err = addResponseErrorMiddleware(stack); err != nil {
114		return err
115	}
116	if err = addRequestResponseLogging(stack, options); err != nil {
117		return err
118	}
119	return nil
120}
121
122// ListCollectionsAPIClient is a client that implements the ListCollections
123// operation.
124type ListCollectionsAPIClient interface {
125	ListCollections(context.Context, *ListCollectionsInput, ...func(*Options)) (*ListCollectionsOutput, error)
126}
127
128var _ ListCollectionsAPIClient = (*Client)(nil)
129
130// ListCollectionsPaginatorOptions is the paginator options for ListCollections
131type ListCollectionsPaginatorOptions struct {
132	// Maximum number of collection IDs to return.
133	Limit int32
134
135	// Set to true if pagination should stop if the service returns a pagination token
136	// that matches the most recent token provided to the service.
137	StopOnDuplicateToken bool
138}
139
140// ListCollectionsPaginator is a paginator for ListCollections
141type ListCollectionsPaginator struct {
142	options   ListCollectionsPaginatorOptions
143	client    ListCollectionsAPIClient
144	params    *ListCollectionsInput
145	nextToken *string
146	firstPage bool
147}
148
149// NewListCollectionsPaginator returns a new ListCollectionsPaginator
150func NewListCollectionsPaginator(client ListCollectionsAPIClient, params *ListCollectionsInput, optFns ...func(*ListCollectionsPaginatorOptions)) *ListCollectionsPaginator {
151	if params == nil {
152		params = &ListCollectionsInput{}
153	}
154
155	options := ListCollectionsPaginatorOptions{}
156	if params.MaxResults != nil {
157		options.Limit = *params.MaxResults
158	}
159
160	for _, fn := range optFns {
161		fn(&options)
162	}
163
164	return &ListCollectionsPaginator{
165		options:   options,
166		client:    client,
167		params:    params,
168		firstPage: true,
169	}
170}
171
172// HasMorePages returns a boolean indicating whether more pages are available
173func (p *ListCollectionsPaginator) HasMorePages() bool {
174	return p.firstPage || p.nextToken != nil
175}
176
177// NextPage retrieves the next ListCollections page.
178func (p *ListCollectionsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListCollectionsOutput, error) {
179	if !p.HasMorePages() {
180		return nil, fmt.Errorf("no more pages available")
181	}
182
183	params := *p.params
184	params.NextToken = p.nextToken
185
186	var limit *int32
187	if p.options.Limit > 0 {
188		limit = &p.options.Limit
189	}
190	params.MaxResults = limit
191
192	result, err := p.client.ListCollections(ctx, &params, optFns...)
193	if err != nil {
194		return nil, err
195	}
196	p.firstPage = false
197
198	prevToken := p.nextToken
199	p.nextToken = result.NextToken
200
201	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
202		p.nextToken = nil
203	}
204
205	return result, nil
206}
207
208func newServiceMetadataMiddleware_opListCollections(region string) *awsmiddleware.RegisterServiceMetadata {
209	return &awsmiddleware.RegisterServiceMetadata{
210		Region:        region,
211		ServiceID:     ServiceID,
212		SigningName:   "rekognition",
213		OperationName: "ListCollections",
214	}
215}
216