1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package mediastore
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/mediastore/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the properties of all containers in AWS Elemental MediaStore. You can
16// query to receive all the containers in one response. Or you can include the
17// MaxResults parameter to receive a limited number of containers in each response.
18// In this case, the response includes a token. To get the next set of containers,
19// send the command again, this time with the NextToken parameter (with the
20// returned token as its value). The next set of responses appears, with a token if
21// there are still more containers to receive. See also DescribeContainer, which
22// gets the properties of one container.
23func (c *Client) ListContainers(ctx context.Context, params *ListContainersInput, optFns ...func(*Options)) (*ListContainersOutput, error) {
24	if params == nil {
25		params = &ListContainersInput{}
26	}
27
28	result, metadata, err := c.invokeOperation(ctx, "ListContainers", params, optFns, addOperationListContainersMiddlewares)
29	if err != nil {
30		return nil, err
31	}
32
33	out := result.(*ListContainersOutput)
34	out.ResultMetadata = metadata
35	return out, nil
36}
37
38type ListContainersInput struct {
39
40	// Enter the maximum number of containers in the response. Use from 1 to 255
41	// characters.
42	MaxResults *int32
43
44	// Only if you used MaxResults in the first command, enter the token (which was
45	// included in the previous response) to obtain the next set of containers. This
46	// token is included in a response only if there actually are more containers to
47	// list.
48	NextToken *string
49}
50
51type ListContainersOutput struct {
52
53	// The names of the containers.
54	//
55	// This member is required.
56	Containers []types.Container
57
58	// NextToken is the token to use in the next call to ListContainers. This token is
59	// returned only if you included the MaxResults tag in the original command, and
60	// only if there are still containers to return.
61	NextToken *string
62
63	// Metadata pertaining to the operation's result.
64	ResultMetadata middleware.Metadata
65}
66
67func addOperationListContainersMiddlewares(stack *middleware.Stack, options Options) (err error) {
68	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListContainers{}, middleware.After)
69	if err != nil {
70		return err
71	}
72	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListContainers{}, middleware.After)
73	if err != nil {
74		return err
75	}
76	if err = addSetLoggerMiddleware(stack, options); err != nil {
77		return err
78	}
79	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
80		return err
81	}
82	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
83		return err
84	}
85	if err = addResolveEndpointMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
89		return err
90	}
91	if err = addRetryMiddlewares(stack, options); err != nil {
92		return err
93	}
94	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
95		return err
96	}
97	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
98		return err
99	}
100	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
101		return err
102	}
103	if err = addClientUserAgent(stack); err != nil {
104		return err
105	}
106	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
107		return err
108	}
109	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
110		return err
111	}
112	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListContainers(options.Region), middleware.Before); err != nil {
113		return err
114	}
115	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
116		return err
117	}
118	if err = addResponseErrorMiddleware(stack); err != nil {
119		return err
120	}
121	if err = addRequestResponseLogging(stack, options); err != nil {
122		return err
123	}
124	return nil
125}
126
127// ListContainersAPIClient is a client that implements the ListContainers
128// operation.
129type ListContainersAPIClient interface {
130	ListContainers(context.Context, *ListContainersInput, ...func(*Options)) (*ListContainersOutput, error)
131}
132
133var _ ListContainersAPIClient = (*Client)(nil)
134
135// ListContainersPaginatorOptions is the paginator options for ListContainers
136type ListContainersPaginatorOptions struct {
137	// Enter the maximum number of containers in the response. Use from 1 to 255
138	// characters.
139	Limit int32
140
141	// Set to true if pagination should stop if the service returns a pagination token
142	// that matches the most recent token provided to the service.
143	StopOnDuplicateToken bool
144}
145
146// ListContainersPaginator is a paginator for ListContainers
147type ListContainersPaginator struct {
148	options   ListContainersPaginatorOptions
149	client    ListContainersAPIClient
150	params    *ListContainersInput
151	nextToken *string
152	firstPage bool
153}
154
155// NewListContainersPaginator returns a new ListContainersPaginator
156func NewListContainersPaginator(client ListContainersAPIClient, params *ListContainersInput, optFns ...func(*ListContainersPaginatorOptions)) *ListContainersPaginator {
157	options := ListContainersPaginatorOptions{}
158	if params.MaxResults != nil {
159		options.Limit = *params.MaxResults
160	}
161
162	for _, fn := range optFns {
163		fn(&options)
164	}
165
166	if params == nil {
167		params = &ListContainersInput{}
168	}
169
170	return &ListContainersPaginator{
171		options:   options,
172		client:    client,
173		params:    params,
174		firstPage: true,
175	}
176}
177
178// HasMorePages returns a boolean indicating whether more pages are available
179func (p *ListContainersPaginator) HasMorePages() bool {
180	return p.firstPage || p.nextToken != nil
181}
182
183// NextPage retrieves the next ListContainers page.
184func (p *ListContainersPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListContainersOutput, error) {
185	if !p.HasMorePages() {
186		return nil, fmt.Errorf("no more pages available")
187	}
188
189	params := *p.params
190	params.NextToken = p.nextToken
191
192	var limit *int32
193	if p.options.Limit > 0 {
194		limit = &p.options.Limit
195	}
196	params.MaxResults = limit
197
198	result, err := p.client.ListContainers(ctx, &params, optFns...)
199	if err != nil {
200		return nil, err
201	}
202	p.firstPage = false
203
204	prevToken := p.nextToken
205	p.nextToken = result.NextToken
206
207	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
208		p.nextToken = nil
209	}
210
211	return result, nil
212}
213
214func newServiceMetadataMiddleware_opListContainers(region string) *awsmiddleware.RegisterServiceMetadata {
215	return &awsmiddleware.RegisterServiceMetadata{
216		Region:        region,
217		ServiceID:     ServiceID,
218		SigningName:   "mediastore",
219		OperationName: "ListContainers",
220	}
221}
222