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