1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package transcribe 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/transcribe/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of vocabularies that match the specified criteria. If no criteria 16// are specified, returns the entire list of vocabularies. 17func (c *Client) ListVocabularies(ctx context.Context, params *ListVocabulariesInput, optFns ...func(*Options)) (*ListVocabulariesOutput, error) { 18 if params == nil { 19 params = &ListVocabulariesInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListVocabularies", params, optFns, c.addOperationListVocabulariesMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListVocabulariesOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type ListVocabulariesInput struct { 33 34 // The maximum number of vocabularies to return in each page of results. If there 35 // are fewer results than the value you specify, only the actual results are 36 // returned. If you do not specify a value, the default of 5 is used. 37 MaxResults *int32 38 39 // When specified, the vocabularies returned in the list are limited to 40 // vocabularies whose name contains the specified string. The search is not case 41 // sensitive, ListVocabularies returns both "vocabularyname" and "VocabularyName" 42 // in the response list. 43 NameContains *string 44 45 // If the result of the previous request to ListVocabularies was truncated, include 46 // the NextToken to fetch the next set of jobs. 47 NextToken *string 48 49 // When specified, only returns vocabularies with the VocabularyState field equal 50 // to the specified state. 51 StateEquals types.VocabularyState 52 53 noSmithyDocumentSerde 54} 55 56type ListVocabulariesOutput struct { 57 58 // The ListVocabularies operation returns a page of vocabularies at a time. The 59 // maximum size of the page is set in the MaxResults parameter. If there are more 60 // jobs in the list than will fit on the page, Amazon Transcribe returns the 61 // NextPage token. To return in the next page of jobs, include the token in the 62 // next request to the ListVocabularies operation. 63 NextToken *string 64 65 // The requested vocabulary state. 66 Status types.VocabularyState 67 68 // A list of objects that describe the vocabularies that match the search criteria 69 // in the request. 70 Vocabularies []types.VocabularyInfo 71 72 // Metadata pertaining to the operation's result. 73 ResultMetadata middleware.Metadata 74 75 noSmithyDocumentSerde 76} 77 78func (c *Client) addOperationListVocabulariesMiddlewares(stack *middleware.Stack, options Options) (err error) { 79 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListVocabularies{}, middleware.After) 80 if err != nil { 81 return err 82 } 83 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListVocabularies{}, middleware.After) 84 if err != nil { 85 return err 86 } 87 if err = addSetLoggerMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 91 return err 92 } 93 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 94 return err 95 } 96 if err = addResolveEndpointMiddleware(stack, options); err != nil { 97 return err 98 } 99 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 100 return err 101 } 102 if err = addRetryMiddlewares(stack, options); err != nil { 103 return err 104 } 105 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 106 return err 107 } 108 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 109 return err 110 } 111 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 112 return err 113 } 114 if err = addClientUserAgent(stack); err != nil { 115 return err 116 } 117 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 118 return err 119 } 120 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 121 return err 122 } 123 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListVocabularies(options.Region), middleware.Before); err != nil { 124 return err 125 } 126 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 127 return err 128 } 129 if err = addResponseErrorMiddleware(stack); err != nil { 130 return err 131 } 132 if err = addRequestResponseLogging(stack, options); err != nil { 133 return err 134 } 135 return nil 136} 137 138// ListVocabulariesAPIClient is a client that implements the ListVocabularies 139// operation. 140type ListVocabulariesAPIClient interface { 141 ListVocabularies(context.Context, *ListVocabulariesInput, ...func(*Options)) (*ListVocabulariesOutput, error) 142} 143 144var _ ListVocabulariesAPIClient = (*Client)(nil) 145 146// ListVocabulariesPaginatorOptions is the paginator options for ListVocabularies 147type ListVocabulariesPaginatorOptions struct { 148 // The maximum number of vocabularies to return in each page of results. If there 149 // are fewer results than the value you specify, only the actual results are 150 // returned. If you do not specify a value, the default of 5 is used. 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// ListVocabulariesPaginator is a paginator for ListVocabularies 159type ListVocabulariesPaginator struct { 160 options ListVocabulariesPaginatorOptions 161 client ListVocabulariesAPIClient 162 params *ListVocabulariesInput 163 nextToken *string 164 firstPage bool 165} 166 167// NewListVocabulariesPaginator returns a new ListVocabulariesPaginator 168func NewListVocabulariesPaginator(client ListVocabulariesAPIClient, params *ListVocabulariesInput, optFns ...func(*ListVocabulariesPaginatorOptions)) *ListVocabulariesPaginator { 169 if params == nil { 170 params = &ListVocabulariesInput{} 171 } 172 173 options := ListVocabulariesPaginatorOptions{} 174 if params.MaxResults != nil { 175 options.Limit = *params.MaxResults 176 } 177 178 for _, fn := range optFns { 179 fn(&options) 180 } 181 182 return &ListVocabulariesPaginator{ 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 *ListVocabulariesPaginator) HasMorePages() bool { 192 return p.firstPage || p.nextToken != nil 193} 194 195// NextPage retrieves the next ListVocabularies page. 196func (p *ListVocabulariesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListVocabulariesOutput, 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.ListVocabularies(ctx, ¶ms, 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_opListVocabularies(region string) *awsmiddleware.RegisterServiceMetadata { 227 return &awsmiddleware.RegisterServiceMetadata{ 228 Region: region, 229 ServiceID: ServiceID, 230 SigningName: "transcribe", 231 OperationName: "ListVocabularies", 232 } 233} 234