1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package appmesh
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/appmesh/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns a list of existing virtual gateways in a service mesh.
16func (c *Client) ListVirtualGateways(ctx context.Context, params *ListVirtualGatewaysInput, optFns ...func(*Options)) (*ListVirtualGatewaysOutput, error) {
17	if params == nil {
18		params = &ListVirtualGatewaysInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListVirtualGateways", params, optFns, c.addOperationListVirtualGatewaysMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListVirtualGatewaysOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListVirtualGatewaysInput struct {
32
33	// The name of the service mesh to list virtual gateways in.
34	//
35	// This member is required.
36	MeshName *string
37
38	// The maximum number of results returned by ListVirtualGateways in paginated
39	// output. When you use this parameter, ListVirtualGateways returns only limit
40	// results in a single page along with a nextToken response element. You can see
41	// the remaining results of the initial request by sending another
42	// ListVirtualGateways request with the returned nextToken value. This value can be
43	// between 1 and 100. If you don't use this parameter, ListVirtualGateways returns
44	// up to 100 results and a nextToken value if applicable.
45	Limit *int32
46
47	// The AWS IAM account ID of the service mesh owner. If the account ID is not your
48	// own, then it's the ID of the account that shared the mesh with your account. For
49	// more information about mesh sharing, see Working with shared meshes
50	// (https://docs.aws.amazon.com/app-mesh/latest/userguide/sharing.html).
51	MeshOwner *string
52
53	// The nextToken value returned from a previous paginated ListVirtualGateways
54	// request where limit was used and the results exceeded the value of that
55	// parameter. Pagination continues from the end of the previous results that
56	// returned the nextToken value.
57	NextToken *string
58
59	noSmithyDocumentSerde
60}
61
62type ListVirtualGatewaysOutput struct {
63
64	// The list of existing virtual gateways for the specified service mesh.
65	//
66	// This member is required.
67	VirtualGateways []types.VirtualGatewayRef
68
69	// The nextToken value to include in a future ListVirtualGateways request. When the
70	// results of a ListVirtualGateways request exceed limit, you can use this value to
71	// retrieve the next page of results. This value is null when there are no more
72	// results to return.
73	NextToken *string
74
75	// Metadata pertaining to the operation's result.
76	ResultMetadata middleware.Metadata
77
78	noSmithyDocumentSerde
79}
80
81func (c *Client) addOperationListVirtualGatewaysMiddlewares(stack *middleware.Stack, options Options) (err error) {
82	err = stack.Serialize.Add(&awsRestjson1_serializeOpListVirtualGateways{}, middleware.After)
83	if err != nil {
84		return err
85	}
86	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListVirtualGateways{}, middleware.After)
87	if err != nil {
88		return err
89	}
90	if err = addSetLoggerMiddleware(stack, options); err != nil {
91		return err
92	}
93	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
97		return err
98	}
99	if err = addResolveEndpointMiddleware(stack, options); err != nil {
100		return err
101	}
102	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
103		return err
104	}
105	if err = addRetryMiddlewares(stack, options); err != nil {
106		return err
107	}
108	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
112		return err
113	}
114	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
115		return err
116	}
117	if err = addClientUserAgent(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addOpListVirtualGatewaysValidationMiddleware(stack); err != nil {
127		return err
128	}
129	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListVirtualGateways(options.Region), middleware.Before); err != nil {
130		return err
131	}
132	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
133		return err
134	}
135	if err = addResponseErrorMiddleware(stack); err != nil {
136		return err
137	}
138	if err = addRequestResponseLogging(stack, options); err != nil {
139		return err
140	}
141	return nil
142}
143
144// ListVirtualGatewaysAPIClient is a client that implements the ListVirtualGateways
145// operation.
146type ListVirtualGatewaysAPIClient interface {
147	ListVirtualGateways(context.Context, *ListVirtualGatewaysInput, ...func(*Options)) (*ListVirtualGatewaysOutput, error)
148}
149
150var _ ListVirtualGatewaysAPIClient = (*Client)(nil)
151
152// ListVirtualGatewaysPaginatorOptions is the paginator options for
153// ListVirtualGateways
154type ListVirtualGatewaysPaginatorOptions struct {
155	// The maximum number of results returned by ListVirtualGateways in paginated
156	// output. When you use this parameter, ListVirtualGateways returns only limit
157	// results in a single page along with a nextToken response element. You can see
158	// the remaining results of the initial request by sending another
159	// ListVirtualGateways request with the returned nextToken value. This value can be
160	// between 1 and 100. If you don't use this parameter, ListVirtualGateways returns
161	// up to 100 results and a nextToken value if applicable.
162	Limit int32
163
164	// Set to true if pagination should stop if the service returns a pagination token
165	// that matches the most recent token provided to the service.
166	StopOnDuplicateToken bool
167}
168
169// ListVirtualGatewaysPaginator is a paginator for ListVirtualGateways
170type ListVirtualGatewaysPaginator struct {
171	options   ListVirtualGatewaysPaginatorOptions
172	client    ListVirtualGatewaysAPIClient
173	params    *ListVirtualGatewaysInput
174	nextToken *string
175	firstPage bool
176}
177
178// NewListVirtualGatewaysPaginator returns a new ListVirtualGatewaysPaginator
179func NewListVirtualGatewaysPaginator(client ListVirtualGatewaysAPIClient, params *ListVirtualGatewaysInput, optFns ...func(*ListVirtualGatewaysPaginatorOptions)) *ListVirtualGatewaysPaginator {
180	if params == nil {
181		params = &ListVirtualGatewaysInput{}
182	}
183
184	options := ListVirtualGatewaysPaginatorOptions{}
185	if params.Limit != nil {
186		options.Limit = *params.Limit
187	}
188
189	for _, fn := range optFns {
190		fn(&options)
191	}
192
193	return &ListVirtualGatewaysPaginator{
194		options:   options,
195		client:    client,
196		params:    params,
197		firstPage: true,
198	}
199}
200
201// HasMorePages returns a boolean indicating whether more pages are available
202func (p *ListVirtualGatewaysPaginator) HasMorePages() bool {
203	return p.firstPage || p.nextToken != nil
204}
205
206// NextPage retrieves the next ListVirtualGateways page.
207func (p *ListVirtualGatewaysPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListVirtualGatewaysOutput, error) {
208	if !p.HasMorePages() {
209		return nil, fmt.Errorf("no more pages available")
210	}
211
212	params := *p.params
213	params.NextToken = p.nextToken
214
215	var limit *int32
216	if p.options.Limit > 0 {
217		limit = &p.options.Limit
218	}
219	params.Limit = limit
220
221	result, err := p.client.ListVirtualGateways(ctx, &params, optFns...)
222	if err != nil {
223		return nil, err
224	}
225	p.firstPage = false
226
227	prevToken := p.nextToken
228	p.nextToken = result.NextToken
229
230	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
231		p.nextToken = nil
232	}
233
234	return result, nil
235}
236
237func newServiceMetadataMiddleware_opListVirtualGateways(region string) *awsmiddleware.RegisterServiceMetadata {
238	return &awsmiddleware.RegisterServiceMetadata{
239		Region:        region,
240		ServiceID:     ServiceID,
241		SigningName:   "appmesh",
242		OperationName: "ListVirtualGateways",
243	}
244}
245