1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package datasync 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/datasync/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of source and destination locations. If you have more locations 16// than are returned in a response (that is, the response returns only a truncated 17// list of your agents), the response contains a token that you can specify in your 18// next request to fetch the next page of locations. 19func (c *Client) ListLocations(ctx context.Context, params *ListLocationsInput, optFns ...func(*Options)) (*ListLocationsOutput, error) { 20 if params == nil { 21 params = &ListLocationsInput{} 22 } 23 24 result, metadata, err := c.invokeOperation(ctx, "ListLocations", params, optFns, addOperationListLocationsMiddlewares) 25 if err != nil { 26 return nil, err 27 } 28 29 out := result.(*ListLocationsOutput) 30 out.ResultMetadata = metadata 31 return out, nil 32} 33 34// ListLocationsRequest 35type ListLocationsInput struct { 36 37 // You can use API filters to narrow down the list of resources returned by 38 // ListLocations. For example, to retrieve all tasks on a specific source location, 39 // you can use ListLocations with filter name LocationType S3 and Operator Equals. 40 Filters []types.LocationFilter 41 42 // The maximum number of locations to return. 43 MaxResults *int32 44 45 // An opaque string that indicates the position at which to begin the next list of 46 // locations. 47 NextToken *string 48} 49 50// ListLocationsResponse 51type ListLocationsOutput struct { 52 53 // An array that contains a list of locations. 54 Locations []types.LocationListEntry 55 56 // An opaque string that indicates the position at which to begin returning the 57 // next list of locations. 58 NextToken *string 59 60 // Metadata pertaining to the operation's result. 61 ResultMetadata middleware.Metadata 62} 63 64func addOperationListLocationsMiddlewares(stack *middleware.Stack, options Options) (err error) { 65 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListLocations{}, middleware.After) 66 if err != nil { 67 return err 68 } 69 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListLocations{}, middleware.After) 70 if err != nil { 71 return err 72 } 73 if err = addSetLoggerMiddleware(stack, options); err != nil { 74 return err 75 } 76 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 77 return err 78 } 79 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 80 return err 81 } 82 if err = addResolveEndpointMiddleware(stack, options); err != nil { 83 return err 84 } 85 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 86 return err 87 } 88 if err = addRetryMiddlewares(stack, options); err != nil { 89 return err 90 } 91 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 92 return err 93 } 94 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 95 return err 96 } 97 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 98 return err 99 } 100 if err = addClientUserAgent(stack); err != nil { 101 return err 102 } 103 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 104 return err 105 } 106 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 107 return err 108 } 109 if err = addOpListLocationsValidationMiddleware(stack); err != nil { 110 return err 111 } 112 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListLocations(options.Region), middleware.Before); err != nil { 113 return err 114 } 115 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 116 return err 117 } 118 if err = addResponseErrorMiddleware(stack); err != nil { 119 return err 120 } 121 if err = addRequestResponseLogging(stack, options); err != nil { 122 return err 123 } 124 return nil 125} 126 127// ListLocationsAPIClient is a client that implements the ListLocations operation. 128type ListLocationsAPIClient interface { 129 ListLocations(context.Context, *ListLocationsInput, ...func(*Options)) (*ListLocationsOutput, error) 130} 131 132var _ ListLocationsAPIClient = (*Client)(nil) 133 134// ListLocationsPaginatorOptions is the paginator options for ListLocations 135type ListLocationsPaginatorOptions struct { 136 // The maximum number of locations to return. 137 Limit int32 138 139 // Set to true if pagination should stop if the service returns a pagination token 140 // that matches the most recent token provided to the service. 141 StopOnDuplicateToken bool 142} 143 144// ListLocationsPaginator is a paginator for ListLocations 145type ListLocationsPaginator struct { 146 options ListLocationsPaginatorOptions 147 client ListLocationsAPIClient 148 params *ListLocationsInput 149 nextToken *string 150 firstPage bool 151} 152 153// NewListLocationsPaginator returns a new ListLocationsPaginator 154func NewListLocationsPaginator(client ListLocationsAPIClient, params *ListLocationsInput, optFns ...func(*ListLocationsPaginatorOptions)) *ListLocationsPaginator { 155 if params == nil { 156 params = &ListLocationsInput{} 157 } 158 159 options := ListLocationsPaginatorOptions{} 160 if params.MaxResults != nil { 161 options.Limit = *params.MaxResults 162 } 163 164 for _, fn := range optFns { 165 fn(&options) 166 } 167 168 return &ListLocationsPaginator{ 169 options: options, 170 client: client, 171 params: params, 172 firstPage: true, 173 } 174} 175 176// HasMorePages returns a boolean indicating whether more pages are available 177func (p *ListLocationsPaginator) HasMorePages() bool { 178 return p.firstPage || p.nextToken != nil 179} 180 181// NextPage retrieves the next ListLocations page. 182func (p *ListLocationsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListLocationsOutput, error) { 183 if !p.HasMorePages() { 184 return nil, fmt.Errorf("no more pages available") 185 } 186 187 params := *p.params 188 params.NextToken = p.nextToken 189 190 var limit *int32 191 if p.options.Limit > 0 { 192 limit = &p.options.Limit 193 } 194 params.MaxResults = limit 195 196 result, err := p.client.ListLocations(ctx, ¶ms, optFns...) 197 if err != nil { 198 return nil, err 199 } 200 p.firstPage = false 201 202 prevToken := p.nextToken 203 p.nextToken = result.NextToken 204 205 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 206 p.nextToken = nil 207 } 208 209 return result, nil 210} 211 212func newServiceMetadataMiddleware_opListLocations(region string) *awsmiddleware.RegisterServiceMetadata { 213 return &awsmiddleware.RegisterServiceMetadata{ 214 Region: region, 215 ServiceID: ServiceID, 216 SigningName: "datasync", 217 OperationName: "ListLocations", 218 } 219} 220