1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package kendra 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/kendra/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists the data sources that you have created. 16func (c *Client) ListDataSources(ctx context.Context, params *ListDataSourcesInput, optFns ...func(*Options)) (*ListDataSourcesOutput, error) { 17 if params == nil { 18 params = &ListDataSourcesInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListDataSources", params, optFns, addOperationListDataSourcesMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListDataSourcesOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListDataSourcesInput struct { 32 33 // The identifier of the index that contains the data source. 34 // 35 // This member is required. 36 IndexId *string 37 38 // The maximum number of data sources to return. 39 MaxResults *int32 40 41 // If the previous response was incomplete (because there is more data to 42 // retrieve), Amazon Kendra returns a pagination token in the response. You can use 43 // this pagination token to retrieve the next set of data sources 44 // (DataSourceSummaryItems). 45 NextToken *string 46} 47 48type ListDataSourcesOutput struct { 49 50 // If the response is truncated, Amazon Kendra returns this token that you can use 51 // in the subsequent request to retrieve the next set of data sources. 52 NextToken *string 53 54 // An array of summary information for one or more data sources. 55 SummaryItems []types.DataSourceSummary 56 57 // Metadata pertaining to the operation's result. 58 ResultMetadata middleware.Metadata 59} 60 61func addOperationListDataSourcesMiddlewares(stack *middleware.Stack, options Options) (err error) { 62 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListDataSources{}, middleware.After) 63 if err != nil { 64 return err 65 } 66 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListDataSources{}, 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 = addOpListDataSourcesValidationMiddleware(stack); err != nil { 107 return err 108 } 109 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListDataSources(options.Region), middleware.Before); err != nil { 110 return err 111 } 112 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 113 return err 114 } 115 if err = addResponseErrorMiddleware(stack); err != nil { 116 return err 117 } 118 if err = addRequestResponseLogging(stack, options); err != nil { 119 return err 120 } 121 return nil 122} 123 124// ListDataSourcesAPIClient is a client that implements the ListDataSources 125// operation. 126type ListDataSourcesAPIClient interface { 127 ListDataSources(context.Context, *ListDataSourcesInput, ...func(*Options)) (*ListDataSourcesOutput, error) 128} 129 130var _ ListDataSourcesAPIClient = (*Client)(nil) 131 132// ListDataSourcesPaginatorOptions is the paginator options for ListDataSources 133type ListDataSourcesPaginatorOptions struct { 134 // The maximum number of data sources to return. 135 Limit int32 136 137 // Set to true if pagination should stop if the service returns a pagination token 138 // that matches the most recent token provided to the service. 139 StopOnDuplicateToken bool 140} 141 142// ListDataSourcesPaginator is a paginator for ListDataSources 143type ListDataSourcesPaginator struct { 144 options ListDataSourcesPaginatorOptions 145 client ListDataSourcesAPIClient 146 params *ListDataSourcesInput 147 nextToken *string 148 firstPage bool 149} 150 151// NewListDataSourcesPaginator returns a new ListDataSourcesPaginator 152func NewListDataSourcesPaginator(client ListDataSourcesAPIClient, params *ListDataSourcesInput, optFns ...func(*ListDataSourcesPaginatorOptions)) *ListDataSourcesPaginator { 153 if params == nil { 154 params = &ListDataSourcesInput{} 155 } 156 157 options := ListDataSourcesPaginatorOptions{} 158 if params.MaxResults != nil { 159 options.Limit = *params.MaxResults 160 } 161 162 for _, fn := range optFns { 163 fn(&options) 164 } 165 166 return &ListDataSourcesPaginator{ 167 options: options, 168 client: client, 169 params: params, 170 firstPage: true, 171 } 172} 173 174// HasMorePages returns a boolean indicating whether more pages are available 175func (p *ListDataSourcesPaginator) HasMorePages() bool { 176 return p.firstPage || p.nextToken != nil 177} 178 179// NextPage retrieves the next ListDataSources page. 180func (p *ListDataSourcesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListDataSourcesOutput, error) { 181 if !p.HasMorePages() { 182 return nil, fmt.Errorf("no more pages available") 183 } 184 185 params := *p.params 186 params.NextToken = p.nextToken 187 188 var limit *int32 189 if p.options.Limit > 0 { 190 limit = &p.options.Limit 191 } 192 params.MaxResults = limit 193 194 result, err := p.client.ListDataSources(ctx, ¶ms, optFns...) 195 if err != nil { 196 return nil, err 197 } 198 p.firstPage = false 199 200 prevToken := p.nextToken 201 p.nextToken = result.NextToken 202 203 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 204 p.nextToken = nil 205 } 206 207 return result, nil 208} 209 210func newServiceMetadataMiddleware_opListDataSources(region string) *awsmiddleware.RegisterServiceMetadata { 211 return &awsmiddleware.RegisterServiceMetadata{ 212 Region: region, 213 ServiceID: ServiceID, 214 SigningName: "kendra", 215 OperationName: "ListDataSources", 216 } 217} 218