1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package timestreamwrite
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/timestreamwrite/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// A list of tables, along with the name, status and retention properties of each
16// table.
17func (c *Client) ListTables(ctx context.Context, params *ListTablesInput, optFns ...func(*Options)) (*ListTablesOutput, error) {
18	if params == nil {
19		params = &ListTablesInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListTables", params, optFns, addOperationListTablesMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListTablesOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListTablesInput struct {
33
34	// The name of the Timestream database.
35	DatabaseName *string
36
37	// The total number of items to return in the output. If the total number of items
38	// available is more than the value specified, a NextToken is provided in the
39	// output. To resume pagination, provide the NextToken value as argument of a
40	// subsequent API invocation.
41	MaxResults *int32
42
43	// The pagination token. To resume pagination, provide the NextToken value as
44	// argument of a subsequent API invocation.
45	NextToken *string
46}
47
48type ListTablesOutput struct {
49
50	// A token to specify where to start paginating. This is the NextToken from a
51	// previously truncated response.
52	NextToken *string
53
54	// A list of tables.
55	Tables []types.Table
56
57	// Metadata pertaining to the operation's result.
58	ResultMetadata middleware.Metadata
59}
60
61func addOperationListTablesMiddlewares(stack *middleware.Stack, options Options) (err error) {
62	err = stack.Serialize.Add(&awsAwsjson10_serializeOpListTables{}, middleware.After)
63	if err != nil {
64		return err
65	}
66	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpListTables{}, middleware.After)
67	if err != nil {
68		return err
69	}
70	if err = addSetLoggerMiddleware(stack, options); err != nil {
71		return err
72	}
73	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
74		return err
75	}
76	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
77		return err
78	}
79	if err = addResolveEndpointMiddleware(stack, options); err != nil {
80		return err
81	}
82	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
83		return err
84	}
85	if err = addRetryMiddlewares(stack, options); err != nil {
86		return err
87	}
88	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
89		return err
90	}
91	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
92		return err
93	}
94	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
95		return err
96	}
97	if err = addClientUserAgent(stack); err != nil {
98		return err
99	}
100	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
101		return err
102	}
103	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
104		return err
105	}
106	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTables(options.Region), middleware.Before); err != nil {
107		return err
108	}
109	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
110		return err
111	}
112	if err = addResponseErrorMiddleware(stack); err != nil {
113		return err
114	}
115	if err = addRequestResponseLogging(stack, options); err != nil {
116		return err
117	}
118	return nil
119}
120
121// ListTablesAPIClient is a client that implements the ListTables operation.
122type ListTablesAPIClient interface {
123	ListTables(context.Context, *ListTablesInput, ...func(*Options)) (*ListTablesOutput, error)
124}
125
126var _ ListTablesAPIClient = (*Client)(nil)
127
128// ListTablesPaginatorOptions is the paginator options for ListTables
129type ListTablesPaginatorOptions struct {
130	// The total number of items to return in the output. If the total number of items
131	// available is more than the value specified, a NextToken is provided in the
132	// output. To resume pagination, provide the NextToken value as argument of a
133	// subsequent API invocation.
134	Limit int32
135
136	// Set to true if pagination should stop if the service returns a pagination token
137	// that matches the most recent token provided to the service.
138	StopOnDuplicateToken bool
139}
140
141// ListTablesPaginator is a paginator for ListTables
142type ListTablesPaginator struct {
143	options   ListTablesPaginatorOptions
144	client    ListTablesAPIClient
145	params    *ListTablesInput
146	nextToken *string
147	firstPage bool
148}
149
150// NewListTablesPaginator returns a new ListTablesPaginator
151func NewListTablesPaginator(client ListTablesAPIClient, params *ListTablesInput, optFns ...func(*ListTablesPaginatorOptions)) *ListTablesPaginator {
152	if params == nil {
153		params = &ListTablesInput{}
154	}
155
156	options := ListTablesPaginatorOptions{}
157	if params.MaxResults != nil {
158		options.Limit = *params.MaxResults
159	}
160
161	for _, fn := range optFns {
162		fn(&options)
163	}
164
165	return &ListTablesPaginator{
166		options:   options,
167		client:    client,
168		params:    params,
169		firstPage: true,
170	}
171}
172
173// HasMorePages returns a boolean indicating whether more pages are available
174func (p *ListTablesPaginator) HasMorePages() bool {
175	return p.firstPage || p.nextToken != nil
176}
177
178// NextPage retrieves the next ListTables page.
179func (p *ListTablesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTablesOutput, error) {
180	if !p.HasMorePages() {
181		return nil, fmt.Errorf("no more pages available")
182	}
183
184	params := *p.params
185	params.NextToken = p.nextToken
186
187	var limit *int32
188	if p.options.Limit > 0 {
189		limit = &p.options.Limit
190	}
191	params.MaxResults = limit
192
193	result, err := p.client.ListTables(ctx, &params, optFns...)
194	if err != nil {
195		return nil, err
196	}
197	p.firstPage = false
198
199	prevToken := p.nextToken
200	p.nextToken = result.NextToken
201
202	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
203		p.nextToken = nil
204	}
205
206	return result, nil
207}
208
209func newServiceMetadataMiddleware_opListTables(region string) *awsmiddleware.RegisterServiceMetadata {
210	return &awsmiddleware.RegisterServiceMetadata{
211		Region:        region,
212		ServiceID:     ServiceID,
213		SigningName:   "timestream",
214		OperationName: "ListTables",
215	}
216}
217