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) 14 15// Finds Amazon SageMaker resources that match a search query. Matching resources 16// are returned as a list of SearchRecord objects in the response. You can sort the 17// search results by any resource property in a ascending or descending order. You 18// can query against the following value types: numeric, text, Boolean, and 19// timestamp. 20func (c *Client) Search(ctx context.Context, params *SearchInput, optFns ...func(*Options)) (*SearchOutput, error) { 21 if params == nil { 22 params = &SearchInput{} 23 } 24 25 result, metadata, err := c.invokeOperation(ctx, "Search", params, optFns, addOperationSearchMiddlewares) 26 if err != nil { 27 return nil, err 28 } 29 30 out := result.(*SearchOutput) 31 out.ResultMetadata = metadata 32 return out, nil 33} 34 35type SearchInput struct { 36 37 // The name of the Amazon SageMaker resource to search for. 38 // 39 // This member is required. 40 Resource types.ResourceType 41 42 // The maximum number of results to return. 43 MaxResults *int32 44 45 // If more than MaxResults resources match the specified SearchExpression, the 46 // response includes a NextToken. The NextToken can be passed to the next 47 // SearchRequest to continue retrieving results. 48 NextToken *string 49 50 // A Boolean conditional statement. Resources must satisfy this condition to be 51 // included in search results. You must provide at least one subexpression, filter, 52 // or nested filter. The maximum number of recursive SubExpressions, NestedFilters, 53 // and Filters that can be included in a SearchExpression object is 50. 54 SearchExpression *types.SearchExpression 55 56 // The name of the resource property used to sort the SearchResults. The default is 57 // LastModifiedTime. 58 SortBy *string 59 60 // How SearchResults are ordered. Valid values are Ascending or Descending. The 61 // default is Descending. 62 SortOrder types.SearchSortOrder 63} 64 65type SearchOutput struct { 66 67 // If the result of the previous Search request was truncated, the response 68 // includes a NextToken. To retrieve the next set of results, use the token in the 69 // next request. 70 NextToken *string 71 72 // A list of SearchRecord objects. 73 Results []types.SearchRecord 74 75 // Metadata pertaining to the operation's result. 76 ResultMetadata middleware.Metadata 77} 78 79func addOperationSearchMiddlewares(stack *middleware.Stack, options Options) (err error) { 80 err = stack.Serialize.Add(&awsAwsjson11_serializeOpSearch{}, middleware.After) 81 if err != nil { 82 return err 83 } 84 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpSearch{}, middleware.After) 85 if err != nil { 86 return err 87 } 88 if err = addSetLoggerMiddleware(stack, options); err != nil { 89 return err 90 } 91 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 92 return err 93 } 94 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 95 return err 96 } 97 if err = addResolveEndpointMiddleware(stack, options); err != nil { 98 return err 99 } 100 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 101 return err 102 } 103 if err = addRetryMiddlewares(stack, options); err != nil { 104 return err 105 } 106 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 107 return err 108 } 109 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 110 return err 111 } 112 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 113 return err 114 } 115 if err = addClientUserAgent(stack); err != nil { 116 return err 117 } 118 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 119 return err 120 } 121 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 122 return err 123 } 124 if err = addOpSearchValidationMiddleware(stack); err != nil { 125 return err 126 } 127 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearch(options.Region), middleware.Before); err != nil { 128 return err 129 } 130 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 131 return err 132 } 133 if err = addResponseErrorMiddleware(stack); err != nil { 134 return err 135 } 136 if err = addRequestResponseLogging(stack, options); err != nil { 137 return err 138 } 139 return nil 140} 141 142// SearchAPIClient is a client that implements the Search operation. 143type SearchAPIClient interface { 144 Search(context.Context, *SearchInput, ...func(*Options)) (*SearchOutput, error) 145} 146 147var _ SearchAPIClient = (*Client)(nil) 148 149// SearchPaginatorOptions is the paginator options for Search 150type SearchPaginatorOptions struct { 151 // The maximum number of results to return. 152 Limit int32 153 154 // Set to true if pagination should stop if the service returns a pagination token 155 // that matches the most recent token provided to the service. 156 StopOnDuplicateToken bool 157} 158 159// SearchPaginator is a paginator for Search 160type SearchPaginator struct { 161 options SearchPaginatorOptions 162 client SearchAPIClient 163 params *SearchInput 164 nextToken *string 165 firstPage bool 166} 167 168// NewSearchPaginator returns a new SearchPaginator 169func NewSearchPaginator(client SearchAPIClient, params *SearchInput, optFns ...func(*SearchPaginatorOptions)) *SearchPaginator { 170 if params == nil { 171 params = &SearchInput{} 172 } 173 174 options := SearchPaginatorOptions{} 175 if params.MaxResults != nil { 176 options.Limit = *params.MaxResults 177 } 178 179 for _, fn := range optFns { 180 fn(&options) 181 } 182 183 return &SearchPaginator{ 184 options: options, 185 client: client, 186 params: params, 187 firstPage: true, 188 } 189} 190 191// HasMorePages returns a boolean indicating whether more pages are available 192func (p *SearchPaginator) HasMorePages() bool { 193 return p.firstPage || p.nextToken != nil 194} 195 196// NextPage retrieves the next Search page. 197func (p *SearchPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*SearchOutput, error) { 198 if !p.HasMorePages() { 199 return nil, fmt.Errorf("no more pages available") 200 } 201 202 params := *p.params 203 params.NextToken = p.nextToken 204 205 var limit *int32 206 if p.options.Limit > 0 { 207 limit = &p.options.Limit 208 } 209 params.MaxResults = limit 210 211 result, err := p.client.Search(ctx, ¶ms, optFns...) 212 if err != nil { 213 return nil, err 214 } 215 p.firstPage = false 216 217 prevToken := p.nextToken 218 p.nextToken = result.NextToken 219 220 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 221 p.nextToken = nil 222 } 223 224 return result, nil 225} 226 227func newServiceMetadataMiddleware_opSearch(region string) *awsmiddleware.RegisterServiceMetadata { 228 return &awsmiddleware.RegisterServiceMetadata{ 229 Region: region, 230 ServiceID: ServiceID, 231 SigningName: "sagemaker", 232 OperationName: "Search", 233 } 234} 235