1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package gamelift
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/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Retrieves a collection of fleet resources in an AWS Region. You can call this
15// operation to get fleets in a previously selected default Region (see
16// https://docs.aws.amazon.com/credref/latest/refdocs/setting-global-region.html
17// (https://docs.aws.amazon.com/credref/latest/refdocs/setting-global-region.html)or
18// specify a Region in your request. You can filter the result set to find only
19// those fleets that are deployed with a specific build or script. For fleets that
20// have multiple locations, this operation retrieves fleets based on their home
21// Region only. This operation can be used in the following ways:
22//
23// * To get a list
24// of all fleets in a Region, don't provide a build or script identifier.
25//
26// * To get
27// a list of all fleets where a specific custom game build is deployed, provide the
28// build ID.
29//
30// * To get a list of all Realtime Servers fleets with a specific
31// configuration script, provide the script ID.
32//
33// Use the pagination parameters to
34// retrieve results as a set of sequential pages. If successful, a list of fleet
35// IDs that match the request parameters is returned. A NextToken value is also
36// returned if there are more result pages to retrieve. Fleet resources are not
37// listed in a particular order. Learn more Setting up GameLift fleets
38// (https://docs.aws.amazon.com/gamelift/latest/developerguide/fleets-intro.html)
39// Related actions CreateFleet | UpdateFleetCapacity | PutScalingPolicy |
40// DescribeEC2InstanceLimits | DescribeFleetAttributes |
41// DescribeFleetLocationAttributes | UpdateFleetAttributes | StopFleetActions |
42// DeleteFleet | All APIs by task
43// (https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets)
44func (c *Client) ListFleets(ctx context.Context, params *ListFleetsInput, optFns ...func(*Options)) (*ListFleetsOutput, error) {
45	if params == nil {
46		params = &ListFleetsInput{}
47	}
48
49	result, metadata, err := c.invokeOperation(ctx, "ListFleets", params, optFns, addOperationListFleetsMiddlewares)
50	if err != nil {
51		return nil, err
52	}
53
54	out := result.(*ListFleetsOutput)
55	out.ResultMetadata = metadata
56	return out, nil
57}
58
59// Represents the input for a request operation.
60type ListFleetsInput struct {
61
62	// A unique identifier for the build to request fleets for. Use this parameter to
63	// return only fleets using a specified build. Use either the build ID or ARN
64	// value.
65	BuildId *string
66
67	// The maximum number of results to return. Use this parameter with NextToken to
68	// get results as a set of sequential pages.
69	Limit *int32
70
71	// A token that indicates the start of the next sequential page of results. Use the
72	// token that is returned with a previous call to this operation. To start at the
73	// beginning of the result set, do not specify a value.
74	NextToken *string
75
76	// A unique identifier for the Realtime script to request fleets for. Use this
77	// parameter to return only fleets using a specified script. Use either the script
78	// ID or ARN value.
79	ScriptId *string
80}
81
82// Represents the returned data in response to a request operation.
83type ListFleetsOutput struct {
84
85	// A set of fleet IDs that match the list request. You can retrieve additional
86	// information about all returned fleets by passing this result set to a
87	// DescribeFleetAttributes, DescribeFleetCapacity, or DescribeFleetUtilization
88	// call.
89	FleetIds []string
90
91	// A token that indicates where to resume retrieving results on the next call to
92	// this operation. If no token is returned, these results represent the end of the
93	// list.
94	NextToken *string
95
96	// Metadata pertaining to the operation's result.
97	ResultMetadata middleware.Metadata
98}
99
100func addOperationListFleetsMiddlewares(stack *middleware.Stack, options Options) (err error) {
101	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListFleets{}, middleware.After)
102	if err != nil {
103		return err
104	}
105	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListFleets{}, middleware.After)
106	if err != nil {
107		return err
108	}
109	if err = addSetLoggerMiddleware(stack, options); err != nil {
110		return err
111	}
112	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
116		return err
117	}
118	if err = addResolveEndpointMiddleware(stack, options); err != nil {
119		return err
120	}
121	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
122		return err
123	}
124	if err = addRetryMiddlewares(stack, options); err != nil {
125		return err
126	}
127	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
128		return err
129	}
130	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
131		return err
132	}
133	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
134		return err
135	}
136	if err = addClientUserAgent(stack); err != nil {
137		return err
138	}
139	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
140		return err
141	}
142	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
143		return err
144	}
145	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListFleets(options.Region), middleware.Before); err != nil {
146		return err
147	}
148	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
149		return err
150	}
151	if err = addResponseErrorMiddleware(stack); err != nil {
152		return err
153	}
154	if err = addRequestResponseLogging(stack, options); err != nil {
155		return err
156	}
157	return nil
158}
159
160// ListFleetsAPIClient is a client that implements the ListFleets operation.
161type ListFleetsAPIClient interface {
162	ListFleets(context.Context, *ListFleetsInput, ...func(*Options)) (*ListFleetsOutput, error)
163}
164
165var _ ListFleetsAPIClient = (*Client)(nil)
166
167// ListFleetsPaginatorOptions is the paginator options for ListFleets
168type ListFleetsPaginatorOptions struct {
169	// The maximum number of results to return. Use this parameter with NextToken to
170	// get results as a set of sequential pages.
171	Limit int32
172
173	// Set to true if pagination should stop if the service returns a pagination token
174	// that matches the most recent token provided to the service.
175	StopOnDuplicateToken bool
176}
177
178// ListFleetsPaginator is a paginator for ListFleets
179type ListFleetsPaginator struct {
180	options   ListFleetsPaginatorOptions
181	client    ListFleetsAPIClient
182	params    *ListFleetsInput
183	nextToken *string
184	firstPage bool
185}
186
187// NewListFleetsPaginator returns a new ListFleetsPaginator
188func NewListFleetsPaginator(client ListFleetsAPIClient, params *ListFleetsInput, optFns ...func(*ListFleetsPaginatorOptions)) *ListFleetsPaginator {
189	if params == nil {
190		params = &ListFleetsInput{}
191	}
192
193	options := ListFleetsPaginatorOptions{}
194	if params.Limit != nil {
195		options.Limit = *params.Limit
196	}
197
198	for _, fn := range optFns {
199		fn(&options)
200	}
201
202	return &ListFleetsPaginator{
203		options:   options,
204		client:    client,
205		params:    params,
206		firstPage: true,
207	}
208}
209
210// HasMorePages returns a boolean indicating whether more pages are available
211func (p *ListFleetsPaginator) HasMorePages() bool {
212	return p.firstPage || p.nextToken != nil
213}
214
215// NextPage retrieves the next ListFleets page.
216func (p *ListFleetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListFleetsOutput, error) {
217	if !p.HasMorePages() {
218		return nil, fmt.Errorf("no more pages available")
219	}
220
221	params := *p.params
222	params.NextToken = p.nextToken
223
224	var limit *int32
225	if p.options.Limit > 0 {
226		limit = &p.options.Limit
227	}
228	params.Limit = limit
229
230	result, err := p.client.ListFleets(ctx, &params, optFns...)
231	if err != nil {
232		return nil, err
233	}
234	p.firstPage = false
235
236	prevToken := p.nextToken
237	p.nextToken = result.NextToken
238
239	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
240		p.nextToken = nil
241	}
242
243	return result, nil
244}
245
246func newServiceMetadataMiddleware_opListFleets(region string) *awsmiddleware.RegisterServiceMetadata {
247	return &awsmiddleware.RegisterServiceMetadata{
248		Region:        region,
249		ServiceID:     ServiceID,
250		SigningName:   "gamelift",
251		OperationName: "ListFleets",
252	}
253}
254