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, 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 the response. If there are fewer
35	// results in the list, this response contains only the actual results.
36	MaxResults *int32
37
38	// When specified, the vocabularies returned in the list are limited to
39	// vocabularies whose name contains the specified string. The search is not case
40	// sensitive, ListVocabularies returns both "vocabularyname" and "VocabularyName"
41	// in the response list.
42	NameContains *string
43
44	// If the result of the previous request to ListVocabularies was truncated, include
45	// the NextToken to fetch the next set of jobs.
46	NextToken *string
47
48	// When specified, only returns vocabularies with the VocabularyState field equal
49	// to the specified state.
50	StateEquals types.VocabularyState
51}
52
53type ListVocabulariesOutput struct {
54
55	// The ListVocabularies operation returns a page of vocabularies at a time. The
56	// maximum size of the page is set in the MaxResults parameter. If there are more
57	// jobs in the list than will fit on the page, Amazon Transcribe returns the
58	// NextPage token. To return in the next page of jobs, include the token in the
59	// next request to the ListVocabularies operation.
60	NextToken *string
61
62	// The requested vocabulary state.
63	Status types.VocabularyState
64
65	// A list of objects that describe the vocabularies that match the search criteria
66	// in the request.
67	Vocabularies []types.VocabularyInfo
68
69	// Metadata pertaining to the operation's result.
70	ResultMetadata middleware.Metadata
71}
72
73func addOperationListVocabulariesMiddlewares(stack *middleware.Stack, options Options) (err error) {
74	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListVocabularies{}, middleware.After)
75	if err != nil {
76		return err
77	}
78	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListVocabularies{}, middleware.After)
79	if err != nil {
80		return err
81	}
82	if err = addSetLoggerMiddleware(stack, options); err != nil {
83		return err
84	}
85	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
86		return err
87	}
88	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
89		return err
90	}
91	if err = addResolveEndpointMiddleware(stack, options); err != nil {
92		return err
93	}
94	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
95		return err
96	}
97	if err = addRetryMiddlewares(stack, options); err != nil {
98		return err
99	}
100	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
101		return err
102	}
103	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
104		return err
105	}
106	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
107		return err
108	}
109	if err = addClientUserAgent(stack); err != nil {
110		return err
111	}
112	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
116		return err
117	}
118	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListVocabularies(options.Region), middleware.Before); err != nil {
119		return err
120	}
121	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addResponseErrorMiddleware(stack); err != nil {
125		return err
126	}
127	if err = addRequestResponseLogging(stack, options); err != nil {
128		return err
129	}
130	return nil
131}
132
133// ListVocabulariesAPIClient is a client that implements the ListVocabularies
134// operation.
135type ListVocabulariesAPIClient interface {
136	ListVocabularies(context.Context, *ListVocabulariesInput, ...func(*Options)) (*ListVocabulariesOutput, error)
137}
138
139var _ ListVocabulariesAPIClient = (*Client)(nil)
140
141// ListVocabulariesPaginatorOptions is the paginator options for ListVocabularies
142type ListVocabulariesPaginatorOptions struct {
143	// The maximum number of vocabularies to return in the response. If there are fewer
144	// results in the list, this response contains only the actual results.
145	Limit int32
146
147	// Set to true if pagination should stop if the service returns a pagination token
148	// that matches the most recent token provided to the service.
149	StopOnDuplicateToken bool
150}
151
152// ListVocabulariesPaginator is a paginator for ListVocabularies
153type ListVocabulariesPaginator struct {
154	options   ListVocabulariesPaginatorOptions
155	client    ListVocabulariesAPIClient
156	params    *ListVocabulariesInput
157	nextToken *string
158	firstPage bool
159}
160
161// NewListVocabulariesPaginator returns a new ListVocabulariesPaginator
162func NewListVocabulariesPaginator(client ListVocabulariesAPIClient, params *ListVocabulariesInput, optFns ...func(*ListVocabulariesPaginatorOptions)) *ListVocabulariesPaginator {
163	options := ListVocabulariesPaginatorOptions{}
164	if params.MaxResults != nil {
165		options.Limit = *params.MaxResults
166	}
167
168	for _, fn := range optFns {
169		fn(&options)
170	}
171
172	if params == nil {
173		params = &ListVocabulariesInput{}
174	}
175
176	return &ListVocabulariesPaginator{
177		options:   options,
178		client:    client,
179		params:    params,
180		firstPage: true,
181	}
182}
183
184// HasMorePages returns a boolean indicating whether more pages are available
185func (p *ListVocabulariesPaginator) HasMorePages() bool {
186	return p.firstPage || p.nextToken != nil
187}
188
189// NextPage retrieves the next ListVocabularies page.
190func (p *ListVocabulariesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListVocabulariesOutput, error) {
191	if !p.HasMorePages() {
192		return nil, fmt.Errorf("no more pages available")
193	}
194
195	params := *p.params
196	params.NextToken = p.nextToken
197
198	var limit *int32
199	if p.options.Limit > 0 {
200		limit = &p.options.Limit
201	}
202	params.MaxResults = limit
203
204	result, err := p.client.ListVocabularies(ctx, &params, optFns...)
205	if err != nil {
206		return nil, err
207	}
208	p.firstPage = false
209
210	prevToken := p.nextToken
211	p.nextToken = result.NextToken
212
213	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
214		p.nextToken = nil
215	}
216
217	return result, nil
218}
219
220func newServiceMetadataMiddleware_opListVocabularies(region string) *awsmiddleware.RegisterServiceMetadata {
221	return &awsmiddleware.RegisterServiceMetadata{
222		Region:        region,
223		ServiceID:     ServiceID,
224		SigningName:   "transcribe",
225		OperationName: "ListVocabularies",
226	}
227}
228