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