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