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