1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package databrew
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/databrew/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists all of the DataBrew recipes that are defined.
16func (c *Client) ListRecipes(ctx context.Context, params *ListRecipesInput, optFns ...func(*Options)) (*ListRecipesOutput, error) {
17	if params == nil {
18		params = &ListRecipesInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListRecipes", params, optFns, addOperationListRecipesMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListRecipesOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListRecipesInput struct {
32
33	// The maximum number of results to return in this request.
34	MaxResults *int32
35
36	// The token returned by a previous call to retrieve the next set of results.
37	NextToken *string
38
39	// Return only those recipes with a version identifier of LATEST_WORKING or
40	// LATEST_PUBLISHED. If RecipeVersion is omitted, ListRecipes returns all of the
41	// LATEST_PUBLISHED recipe versions. Valid values: LATEST_WORKING |
42	// LATEST_PUBLISHED
43	RecipeVersion *string
44}
45
46type ListRecipesOutput struct {
47
48	// A list of recipes that are defined.
49	//
50	// This member is required.
51	Recipes []types.Recipe
52
53	// A token that you can use in a subsequent call to retrieve the next set of
54	// results.
55	NextToken *string
56
57	// Metadata pertaining to the operation's result.
58	ResultMetadata middleware.Metadata
59}
60
61func addOperationListRecipesMiddlewares(stack *middleware.Stack, options Options) (err error) {
62	err = stack.Serialize.Add(&awsRestjson1_serializeOpListRecipes{}, middleware.After)
63	if err != nil {
64		return err
65	}
66	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListRecipes{}, 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_opListRecipes(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// ListRecipesAPIClient is a client that implements the ListRecipes operation.
122type ListRecipesAPIClient interface {
123	ListRecipes(context.Context, *ListRecipesInput, ...func(*Options)) (*ListRecipesOutput, error)
124}
125
126var _ ListRecipesAPIClient = (*Client)(nil)
127
128// ListRecipesPaginatorOptions is the paginator options for ListRecipes
129type ListRecipesPaginatorOptions struct {
130	// The maximum number of results to return in this request.
131	Limit int32
132
133	// Set to true if pagination should stop if the service returns a pagination token
134	// that matches the most recent token provided to the service.
135	StopOnDuplicateToken bool
136}
137
138// ListRecipesPaginator is a paginator for ListRecipes
139type ListRecipesPaginator struct {
140	options   ListRecipesPaginatorOptions
141	client    ListRecipesAPIClient
142	params    *ListRecipesInput
143	nextToken *string
144	firstPage bool
145}
146
147// NewListRecipesPaginator returns a new ListRecipesPaginator
148func NewListRecipesPaginator(client ListRecipesAPIClient, params *ListRecipesInput, optFns ...func(*ListRecipesPaginatorOptions)) *ListRecipesPaginator {
149	if params == nil {
150		params = &ListRecipesInput{}
151	}
152
153	options := ListRecipesPaginatorOptions{}
154	if params.MaxResults != nil {
155		options.Limit = *params.MaxResults
156	}
157
158	for _, fn := range optFns {
159		fn(&options)
160	}
161
162	return &ListRecipesPaginator{
163		options:   options,
164		client:    client,
165		params:    params,
166		firstPage: true,
167	}
168}
169
170// HasMorePages returns a boolean indicating whether more pages are available
171func (p *ListRecipesPaginator) HasMorePages() bool {
172	return p.firstPage || p.nextToken != nil
173}
174
175// NextPage retrieves the next ListRecipes page.
176func (p *ListRecipesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListRecipesOutput, error) {
177	if !p.HasMorePages() {
178		return nil, fmt.Errorf("no more pages available")
179	}
180
181	params := *p.params
182	params.NextToken = p.nextToken
183
184	var limit *int32
185	if p.options.Limit > 0 {
186		limit = &p.options.Limit
187	}
188	params.MaxResults = limit
189
190	result, err := p.client.ListRecipes(ctx, &params, optFns...)
191	if err != nil {
192		return nil, err
193	}
194	p.firstPage = false
195
196	prevToken := p.nextToken
197	p.nextToken = result.NextToken
198
199	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
200		p.nextToken = nil
201	}
202
203	return result, nil
204}
205
206func newServiceMetadataMiddleware_opListRecipes(region string) *awsmiddleware.RegisterServiceMetadata {
207	return &awsmiddleware.RegisterServiceMetadata{
208		Region:        region,
209		ServiceID:     ServiceID,
210		SigningName:   "databrew",
211		OperationName: "ListRecipes",
212	}
213}
214