1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package mediastoredata
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/mediastoredata/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Provides a list of metadata entries about folders and objects in the specified
16// folder.
17func (c *Client) ListItems(ctx context.Context, params *ListItemsInput, optFns ...func(*Options)) (*ListItemsOutput, error) {
18	if params == nil {
19		params = &ListItemsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListItems", params, optFns, addOperationListItemsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListItemsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListItemsInput struct {
33
34	// The maximum number of results to return per API request. For example, you submit
35	// a ListItems request with MaxResults set at 500. Although 2,000 items match your
36	// request, the service returns no more than the first 500 items. (The service also
37	// returns a NextToken value that you can use to fetch the next batch of results.)
38	// The service might return fewer results than the MaxResults value. If MaxResults
39	// is not included in the request, the service defaults to pagination with a
40	// maximum of 1,000 results per page.
41	MaxResults *int32
42
43	// The token that identifies which batch of results that you want to see. For
44	// example, you submit a ListItems request with MaxResults set at 500. The service
45	// returns the first batch of results (up to 500) and a NextToken value. To see the
46	// next batch of results, you can submit the ListItems request a second time and
47	// specify the NextToken value. Tokens expire after 15 minutes.
48	NextToken *string
49
50	// The path in the container from which to retrieve items. Format: //
51	Path *string
52}
53
54type ListItemsOutput struct {
55
56	// The metadata entries for the folders and objects at the requested path.
57	Items []types.Item
58
59	// The token that can be used in a request to view the next set of results. For
60	// example, you submit a ListItems request that matches 2,000 items with MaxResults
61	// set at 500. The service returns the first batch of results (up to 500) and a
62	// NextToken value that can be used to fetch the next batch of results.
63	NextToken *string
64
65	// Metadata pertaining to the operation's result.
66	ResultMetadata middleware.Metadata
67}
68
69func addOperationListItemsMiddlewares(stack *middleware.Stack, options Options) (err error) {
70	err = stack.Serialize.Add(&awsRestjson1_serializeOpListItems{}, middleware.After)
71	if err != nil {
72		return err
73	}
74	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListItems{}, middleware.After)
75	if err != nil {
76		return err
77	}
78	if err = addSetLoggerMiddleware(stack, options); err != nil {
79		return err
80	}
81	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
82		return err
83	}
84	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
85		return err
86	}
87	if err = addResolveEndpointMiddleware(stack, options); err != nil {
88		return err
89	}
90	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
91		return err
92	}
93	if err = addRetryMiddlewares(stack, options); err != nil {
94		return err
95	}
96	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
97		return err
98	}
99	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
100		return err
101	}
102	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
103		return err
104	}
105	if err = addClientUserAgent(stack); err != nil {
106		return err
107	}
108	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
112		return err
113	}
114	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListItems(options.Region), middleware.Before); err != nil {
115		return err
116	}
117	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
118		return err
119	}
120	if err = addResponseErrorMiddleware(stack); err != nil {
121		return err
122	}
123	if err = addRequestResponseLogging(stack, options); err != nil {
124		return err
125	}
126	return nil
127}
128
129// ListItemsAPIClient is a client that implements the ListItems operation.
130type ListItemsAPIClient interface {
131	ListItems(context.Context, *ListItemsInput, ...func(*Options)) (*ListItemsOutput, error)
132}
133
134var _ ListItemsAPIClient = (*Client)(nil)
135
136// ListItemsPaginatorOptions is the paginator options for ListItems
137type ListItemsPaginatorOptions struct {
138	// The maximum number of results to return per API request. For example, you submit
139	// a ListItems request with MaxResults set at 500. Although 2,000 items match your
140	// request, the service returns no more than the first 500 items. (The service also
141	// returns a NextToken value that you can use to fetch the next batch of results.)
142	// The service might return fewer results than the MaxResults value. If MaxResults
143	// is not included in the request, the service defaults to pagination with a
144	// maximum of 1,000 results per page.
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// ListItemsPaginator is a paginator for ListItems
153type ListItemsPaginator struct {
154	options   ListItemsPaginatorOptions
155	client    ListItemsAPIClient
156	params    *ListItemsInput
157	nextToken *string
158	firstPage bool
159}
160
161// NewListItemsPaginator returns a new ListItemsPaginator
162func NewListItemsPaginator(client ListItemsAPIClient, params *ListItemsInput, optFns ...func(*ListItemsPaginatorOptions)) *ListItemsPaginator {
163	if params == nil {
164		params = &ListItemsInput{}
165	}
166
167	options := ListItemsPaginatorOptions{}
168	if params.MaxResults != nil {
169		options.Limit = *params.MaxResults
170	}
171
172	for _, fn := range optFns {
173		fn(&options)
174	}
175
176	return &ListItemsPaginator{
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 *ListItemsPaginator) HasMorePages() bool {
186	return p.firstPage || p.nextToken != nil
187}
188
189// NextPage retrieves the next ListItems page.
190func (p *ListItemsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListItemsOutput, 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.ListItems(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_opListItems(region string) *awsmiddleware.RegisterServiceMetadata {
221	return &awsmiddleware.RegisterServiceMetadata{
222		Region:        region,
223		ServiceID:     ServiceID,
224		SigningName:   "mediastore",
225		OperationName: "ListItems",
226	}
227}
228