1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package sagemaker
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/sagemaker/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13	"time"
14)
15
16// Lists the machine learning algorithms that have been created.
17func (c *Client) ListAlgorithms(ctx context.Context, params *ListAlgorithmsInput, optFns ...func(*Options)) (*ListAlgorithmsOutput, error) {
18	if params == nil {
19		params = &ListAlgorithmsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListAlgorithms", params, optFns, c.addOperationListAlgorithmsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListAlgorithmsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListAlgorithmsInput struct {
33
34	// A filter that returns only algorithms created after the specified time
35	// (timestamp).
36	CreationTimeAfter *time.Time
37
38	// A filter that returns only algorithms created before the specified time
39	// (timestamp).
40	CreationTimeBefore *time.Time
41
42	// The maximum number of algorithms to return in the response.
43	MaxResults *int32
44
45	// A string in the algorithm name. This filter returns only algorithms whose name
46	// contains the specified string.
47	NameContains *string
48
49	// If the response to a previous ListAlgorithms request was truncated, the response
50	// includes a NextToken. To retrieve the next set of algorithms, use the token in
51	// the next request.
52	NextToken *string
53
54	// The parameter by which to sort the results. The default is CreationTime.
55	SortBy types.AlgorithmSortBy
56
57	// The sort order for the results. The default is Ascending.
58	SortOrder types.SortOrder
59
60	noSmithyDocumentSerde
61}
62
63type ListAlgorithmsOutput struct {
64
65	// >An array of AlgorithmSummary objects, each of which lists an algorithm.
66	//
67	// This member is required.
68	AlgorithmSummaryList []types.AlgorithmSummary
69
70	// If the response is truncated, Amazon SageMaker returns this token. To retrieve
71	// the next set of algorithms, use it in the subsequent request.
72	NextToken *string
73
74	// Metadata pertaining to the operation's result.
75	ResultMetadata middleware.Metadata
76
77	noSmithyDocumentSerde
78}
79
80func (c *Client) addOperationListAlgorithmsMiddlewares(stack *middleware.Stack, options Options) (err error) {
81	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListAlgorithms{}, middleware.After)
82	if err != nil {
83		return err
84	}
85	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListAlgorithms{}, middleware.After)
86	if err != nil {
87		return err
88	}
89	if err = addSetLoggerMiddleware(stack, options); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
93		return err
94	}
95	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
96		return err
97	}
98	if err = addResolveEndpointMiddleware(stack, options); err != nil {
99		return err
100	}
101	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
102		return err
103	}
104	if err = addRetryMiddlewares(stack, options); err != nil {
105		return err
106	}
107	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
108		return err
109	}
110	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
111		return err
112	}
113	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
114		return err
115	}
116	if err = addClientUserAgent(stack); err != nil {
117		return err
118	}
119	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
120		return err
121	}
122	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
123		return err
124	}
125	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAlgorithms(options.Region), middleware.Before); err != nil {
126		return err
127	}
128	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addResponseErrorMiddleware(stack); err != nil {
132		return err
133	}
134	if err = addRequestResponseLogging(stack, options); err != nil {
135		return err
136	}
137	return nil
138}
139
140// ListAlgorithmsAPIClient is a client that implements the ListAlgorithms
141// operation.
142type ListAlgorithmsAPIClient interface {
143	ListAlgorithms(context.Context, *ListAlgorithmsInput, ...func(*Options)) (*ListAlgorithmsOutput, error)
144}
145
146var _ ListAlgorithmsAPIClient = (*Client)(nil)
147
148// ListAlgorithmsPaginatorOptions is the paginator options for ListAlgorithms
149type ListAlgorithmsPaginatorOptions struct {
150	// The maximum number of algorithms to return in the response.
151	Limit int32
152
153	// Set to true if pagination should stop if the service returns a pagination token
154	// that matches the most recent token provided to the service.
155	StopOnDuplicateToken bool
156}
157
158// ListAlgorithmsPaginator is a paginator for ListAlgorithms
159type ListAlgorithmsPaginator struct {
160	options   ListAlgorithmsPaginatorOptions
161	client    ListAlgorithmsAPIClient
162	params    *ListAlgorithmsInput
163	nextToken *string
164	firstPage bool
165}
166
167// NewListAlgorithmsPaginator returns a new ListAlgorithmsPaginator
168func NewListAlgorithmsPaginator(client ListAlgorithmsAPIClient, params *ListAlgorithmsInput, optFns ...func(*ListAlgorithmsPaginatorOptions)) *ListAlgorithmsPaginator {
169	if params == nil {
170		params = &ListAlgorithmsInput{}
171	}
172
173	options := ListAlgorithmsPaginatorOptions{}
174	if params.MaxResults != nil {
175		options.Limit = *params.MaxResults
176	}
177
178	for _, fn := range optFns {
179		fn(&options)
180	}
181
182	return &ListAlgorithmsPaginator{
183		options:   options,
184		client:    client,
185		params:    params,
186		firstPage: true,
187	}
188}
189
190// HasMorePages returns a boolean indicating whether more pages are available
191func (p *ListAlgorithmsPaginator) HasMorePages() bool {
192	return p.firstPage || p.nextToken != nil
193}
194
195// NextPage retrieves the next ListAlgorithms page.
196func (p *ListAlgorithmsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAlgorithmsOutput, error) {
197	if !p.HasMorePages() {
198		return nil, fmt.Errorf("no more pages available")
199	}
200
201	params := *p.params
202	params.NextToken = p.nextToken
203
204	var limit *int32
205	if p.options.Limit > 0 {
206		limit = &p.options.Limit
207	}
208	params.MaxResults = limit
209
210	result, err := p.client.ListAlgorithms(ctx, &params, optFns...)
211	if err != nil {
212		return nil, err
213	}
214	p.firstPage = false
215
216	prevToken := p.nextToken
217	p.nextToken = result.NextToken
218
219	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
220		p.nextToken = nil
221	}
222
223	return result, nil
224}
225
226func newServiceMetadataMiddleware_opListAlgorithms(region string) *awsmiddleware.RegisterServiceMetadata {
227	return &awsmiddleware.RegisterServiceMetadata{
228		Region:        region,
229		ServiceID:     ServiceID,
230		SigningName:   "sagemaker",
231		OperationName: "ListAlgorithms",
232	}
233}
234