1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package schemas
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/schemas/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Search the schemas
16func (c *Client) SearchSchemas(ctx context.Context, params *SearchSchemasInput, optFns ...func(*Options)) (*SearchSchemasOutput, error) {
17	if params == nil {
18		params = &SearchSchemasInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "SearchSchemas", params, optFns, addOperationSearchSchemasMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*SearchSchemasOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type SearchSchemasInput struct {
32
33	// Specifying this limits the results to only schemas that include the provided
34	// keywords.
35	//
36	// This member is required.
37	Keywords *string
38
39	// The name of the registry.
40	//
41	// This member is required.
42	RegistryName *string
43
44	Limit int32
45
46	// The token that specifies the next page of results to return. To request the
47	// first page, leave NextToken empty. The token will expire in 24 hours, and cannot
48	// be shared with other accounts.
49	NextToken *string
50}
51
52type SearchSchemasOutput struct {
53
54	// The token that specifies the next page of results to return. To request the
55	// first page, leave NextToken empty. The token will expire in 24 hours, and cannot
56	// be shared with other accounts.
57	NextToken *string
58
59	// An array of SearchSchemaSummary information.
60	Schemas []types.SearchSchemaSummary
61
62	// Metadata pertaining to the operation's result.
63	ResultMetadata middleware.Metadata
64}
65
66func addOperationSearchSchemasMiddlewares(stack *middleware.Stack, options Options) (err error) {
67	err = stack.Serialize.Add(&awsRestjson1_serializeOpSearchSchemas{}, middleware.After)
68	if err != nil {
69		return err
70	}
71	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSearchSchemas{}, middleware.After)
72	if err != nil {
73		return err
74	}
75	if err = addSetLoggerMiddleware(stack, options); err != nil {
76		return err
77	}
78	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
79		return err
80	}
81	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
82		return err
83	}
84	if err = addResolveEndpointMiddleware(stack, options); err != nil {
85		return err
86	}
87	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
88		return err
89	}
90	if err = addRetryMiddlewares(stack, options); err != nil {
91		return err
92	}
93	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
94		return err
95	}
96	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
97		return err
98	}
99	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
100		return err
101	}
102	if err = addClientUserAgent(stack); err != nil {
103		return err
104	}
105	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
106		return err
107	}
108	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
109		return err
110	}
111	if err = addOpSearchSchemasValidationMiddleware(stack); err != nil {
112		return err
113	}
114	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearchSchemas(options.Region), middleware.Before); err != nil {
115		return err
116	}
117	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
118		return err
119	}
120	if err = addResponseErrorMiddleware(stack); err != nil {
121		return err
122	}
123	if err = addRequestResponseLogging(stack, options); err != nil {
124		return err
125	}
126	return nil
127}
128
129// SearchSchemasAPIClient is a client that implements the SearchSchemas operation.
130type SearchSchemasAPIClient interface {
131	SearchSchemas(context.Context, *SearchSchemasInput, ...func(*Options)) (*SearchSchemasOutput, error)
132}
133
134var _ SearchSchemasAPIClient = (*Client)(nil)
135
136// SearchSchemasPaginatorOptions is the paginator options for SearchSchemas
137type SearchSchemasPaginatorOptions struct {
138	Limit int32
139
140	// Set to true if pagination should stop if the service returns a pagination token
141	// that matches the most recent token provided to the service.
142	StopOnDuplicateToken bool
143}
144
145// SearchSchemasPaginator is a paginator for SearchSchemas
146type SearchSchemasPaginator struct {
147	options   SearchSchemasPaginatorOptions
148	client    SearchSchemasAPIClient
149	params    *SearchSchemasInput
150	nextToken *string
151	firstPage bool
152}
153
154// NewSearchSchemasPaginator returns a new SearchSchemasPaginator
155func NewSearchSchemasPaginator(client SearchSchemasAPIClient, params *SearchSchemasInput, optFns ...func(*SearchSchemasPaginatorOptions)) *SearchSchemasPaginator {
156	options := SearchSchemasPaginatorOptions{}
157	if params.Limit != 0 {
158		options.Limit = params.Limit
159	}
160
161	for _, fn := range optFns {
162		fn(&options)
163	}
164
165	if params == nil {
166		params = &SearchSchemasInput{}
167	}
168
169	return &SearchSchemasPaginator{
170		options:   options,
171		client:    client,
172		params:    params,
173		firstPage: true,
174	}
175}
176
177// HasMorePages returns a boolean indicating whether more pages are available
178func (p *SearchSchemasPaginator) HasMorePages() bool {
179	return p.firstPage || p.nextToken != nil
180}
181
182// NextPage retrieves the next SearchSchemas page.
183func (p *SearchSchemasPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*SearchSchemasOutput, error) {
184	if !p.HasMorePages() {
185		return nil, fmt.Errorf("no more pages available")
186	}
187
188	params := *p.params
189	params.NextToken = p.nextToken
190
191	params.Limit = p.options.Limit
192
193	result, err := p.client.SearchSchemas(ctx, &params, optFns...)
194	if err != nil {
195		return nil, err
196	}
197	p.firstPage = false
198
199	prevToken := p.nextToken
200	p.nextToken = result.NextToken
201
202	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
203		p.nextToken = nil
204	}
205
206	return result, nil
207}
208
209func newServiceMetadataMiddleware_opSearchSchemas(region string) *awsmiddleware.RegisterServiceMetadata {
210	return &awsmiddleware.RegisterServiceMetadata{
211		Region:        region,
212		ServiceID:     ServiceID,
213		SigningName:   "schemas",
214		OperationName: "SearchSchemas",
215	}
216}
217