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, 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
61type ListAlgorithmsOutput struct {
62
63	// >An array of AlgorithmSummary objects, each of which lists an algorithm.
64	//
65	// This member is required.
66	AlgorithmSummaryList []types.AlgorithmSummary
67
68	// If the response is truncated, Amazon SageMaker returns this token. To retrieve
69	// the next set of algorithms, use it in the subsequent request.
70	NextToken *string
71
72	// Metadata pertaining to the operation's result.
73	ResultMetadata middleware.Metadata
74}
75
76func addOperationListAlgorithmsMiddlewares(stack *middleware.Stack, options Options) (err error) {
77	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListAlgorithms{}, middleware.After)
78	if err != nil {
79		return err
80	}
81	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListAlgorithms{}, middleware.After)
82	if err != nil {
83		return err
84	}
85	if err = addSetLoggerMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
89		return err
90	}
91	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
92		return err
93	}
94	if err = addResolveEndpointMiddleware(stack, options); err != nil {
95		return err
96	}
97	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
98		return err
99	}
100	if err = addRetryMiddlewares(stack, options); err != nil {
101		return err
102	}
103	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
104		return err
105	}
106	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
107		return err
108	}
109	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
110		return err
111	}
112	if err = addClientUserAgent(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
116		return err
117	}
118	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
119		return err
120	}
121	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAlgorithms(options.Region), middleware.Before); err != nil {
122		return err
123	}
124	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
125		return err
126	}
127	if err = addResponseErrorMiddleware(stack); err != nil {
128		return err
129	}
130	if err = addRequestResponseLogging(stack, options); err != nil {
131		return err
132	}
133	return nil
134}
135
136// ListAlgorithmsAPIClient is a client that implements the ListAlgorithms
137// operation.
138type ListAlgorithmsAPIClient interface {
139	ListAlgorithms(context.Context, *ListAlgorithmsInput, ...func(*Options)) (*ListAlgorithmsOutput, error)
140}
141
142var _ ListAlgorithmsAPIClient = (*Client)(nil)
143
144// ListAlgorithmsPaginatorOptions is the paginator options for ListAlgorithms
145type ListAlgorithmsPaginatorOptions struct {
146	// The maximum number of algorithms to return in the response.
147	Limit int32
148
149	// Set to true if pagination should stop if the service returns a pagination token
150	// that matches the most recent token provided to the service.
151	StopOnDuplicateToken bool
152}
153
154// ListAlgorithmsPaginator is a paginator for ListAlgorithms
155type ListAlgorithmsPaginator struct {
156	options   ListAlgorithmsPaginatorOptions
157	client    ListAlgorithmsAPIClient
158	params    *ListAlgorithmsInput
159	nextToken *string
160	firstPage bool
161}
162
163// NewListAlgorithmsPaginator returns a new ListAlgorithmsPaginator
164func NewListAlgorithmsPaginator(client ListAlgorithmsAPIClient, params *ListAlgorithmsInput, optFns ...func(*ListAlgorithmsPaginatorOptions)) *ListAlgorithmsPaginator {
165	if params == nil {
166		params = &ListAlgorithmsInput{}
167	}
168
169	options := ListAlgorithmsPaginatorOptions{}
170	if params.MaxResults != nil {
171		options.Limit = *params.MaxResults
172	}
173
174	for _, fn := range optFns {
175		fn(&options)
176	}
177
178	return &ListAlgorithmsPaginator{
179		options:   options,
180		client:    client,
181		params:    params,
182		firstPage: true,
183	}
184}
185
186// HasMorePages returns a boolean indicating whether more pages are available
187func (p *ListAlgorithmsPaginator) HasMorePages() bool {
188	return p.firstPage || p.nextToken != nil
189}
190
191// NextPage retrieves the next ListAlgorithms page.
192func (p *ListAlgorithmsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAlgorithmsOutput, error) {
193	if !p.HasMorePages() {
194		return nil, fmt.Errorf("no more pages available")
195	}
196
197	params := *p.params
198	params.NextToken = p.nextToken
199
200	var limit *int32
201	if p.options.Limit > 0 {
202		limit = &p.options.Limit
203	}
204	params.MaxResults = limit
205
206	result, err := p.client.ListAlgorithms(ctx, &params, optFns...)
207	if err != nil {
208		return nil, err
209	}
210	p.firstPage = false
211
212	prevToken := p.nextToken
213	p.nextToken = result.NextToken
214
215	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
216		p.nextToken = nil
217	}
218
219	return result, nil
220}
221
222func newServiceMetadataMiddleware_opListAlgorithms(region string) *awsmiddleware.RegisterServiceMetadata {
223	return &awsmiddleware.RegisterServiceMetadata{
224		Region:        region,
225		ServiceID:     ServiceID,
226		SigningName:   "sagemaker",
227		OperationName: "ListAlgorithms",
228	}
229}
230