1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package storagegateway 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/storagegateway/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists virtual tapes in your virtual tape library (VTL) and your virtual tape 16// shelf (VTS). You specify the tapes to list by specifying one or more tape Amazon 17// Resource Names (ARNs). If you don't specify a tape ARN, the operation lists all 18// virtual tapes in both your VTL and VTS. This operation supports pagination. By 19// default, the operation returns a maximum of up to 100 tapes. You can optionally 20// specify the Limit parameter in the body to limit the number of tapes in the 21// response. If the number of tapes returned in the response is truncated, the 22// response includes a Marker element that you can use in your subsequent request 23// to retrieve the next set of tapes. This operation is only supported in the tape 24// gateway type. 25func (c *Client) ListTapes(ctx context.Context, params *ListTapesInput, optFns ...func(*Options)) (*ListTapesOutput, error) { 26 if params == nil { 27 params = &ListTapesInput{} 28 } 29 30 result, metadata, err := c.invokeOperation(ctx, "ListTapes", params, optFns, addOperationListTapesMiddlewares) 31 if err != nil { 32 return nil, err 33 } 34 35 out := result.(*ListTapesOutput) 36 out.ResultMetadata = metadata 37 return out, nil 38} 39 40// A JSON object that contains one or more of the following fields: 41// 42// * 43// ListTapesInput$Limit 44// 45// * ListTapesInput$Marker 46// 47// * ListTapesInput$TapeARNs 48type ListTapesInput struct { 49 50 // An optional number limit for the tapes in the list returned by this call. 51 Limit *int32 52 53 // A string that indicates the position at which to begin the returned list of 54 // tapes. 55 Marker *string 56 57 // The Amazon Resource Name (ARN) of each of the tapes you want to list. If you 58 // don't specify a tape ARN, the response lists all tapes in both your VTL and VTS. 59 TapeARNs []string 60} 61 62// A JSON object containing the following fields: 63// 64// * ListTapesOutput$Marker 65// 66// * 67// ListTapesOutput$VolumeInfos 68type ListTapesOutput struct { 69 70 // A string that indicates the position at which to begin returning the next list 71 // of tapes. Use the marker in your next request to continue pagination of tapes. 72 // If there are no more tapes to list, this element does not appear in the response 73 // body. 74 Marker *string 75 76 // An array of TapeInfo objects, where each object describes a single tape. If 77 // there are no tapes in the tape library or VTS, then the TapeInfos is an empty 78 // array. 79 TapeInfos []types.TapeInfo 80 81 // Metadata pertaining to the operation's result. 82 ResultMetadata middleware.Metadata 83} 84 85func addOperationListTapesMiddlewares(stack *middleware.Stack, options Options) (err error) { 86 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListTapes{}, middleware.After) 87 if err != nil { 88 return err 89 } 90 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListTapes{}, middleware.After) 91 if err != nil { 92 return err 93 } 94 if err = addSetLoggerMiddleware(stack, options); err != nil { 95 return err 96 } 97 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 98 return err 99 } 100 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 101 return err 102 } 103 if err = addResolveEndpointMiddleware(stack, options); err != nil { 104 return err 105 } 106 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 107 return err 108 } 109 if err = addRetryMiddlewares(stack, options); err != nil { 110 return err 111 } 112 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 113 return err 114 } 115 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 116 return err 117 } 118 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 119 return err 120 } 121 if err = addClientUserAgent(stack); err != nil { 122 return err 123 } 124 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 125 return err 126 } 127 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 128 return err 129 } 130 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTapes(options.Region), middleware.Before); err != nil { 131 return err 132 } 133 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 134 return err 135 } 136 if err = addResponseErrorMiddleware(stack); err != nil { 137 return err 138 } 139 if err = addRequestResponseLogging(stack, options); err != nil { 140 return err 141 } 142 return nil 143} 144 145// ListTapesAPIClient is a client that implements the ListTapes operation. 146type ListTapesAPIClient interface { 147 ListTapes(context.Context, *ListTapesInput, ...func(*Options)) (*ListTapesOutput, error) 148} 149 150var _ ListTapesAPIClient = (*Client)(nil) 151 152// ListTapesPaginatorOptions is the paginator options for ListTapes 153type ListTapesPaginatorOptions struct { 154 // An optional number limit for the tapes in the list returned by this call. 155 Limit int32 156 157 // Set to true if pagination should stop if the service returns a pagination token 158 // that matches the most recent token provided to the service. 159 StopOnDuplicateToken bool 160} 161 162// ListTapesPaginator is a paginator for ListTapes 163type ListTapesPaginator struct { 164 options ListTapesPaginatorOptions 165 client ListTapesAPIClient 166 params *ListTapesInput 167 nextToken *string 168 firstPage bool 169} 170 171// NewListTapesPaginator returns a new ListTapesPaginator 172func NewListTapesPaginator(client ListTapesAPIClient, params *ListTapesInput, optFns ...func(*ListTapesPaginatorOptions)) *ListTapesPaginator { 173 if params == nil { 174 params = &ListTapesInput{} 175 } 176 177 options := ListTapesPaginatorOptions{} 178 if params.Limit != nil { 179 options.Limit = *params.Limit 180 } 181 182 for _, fn := range optFns { 183 fn(&options) 184 } 185 186 return &ListTapesPaginator{ 187 options: options, 188 client: client, 189 params: params, 190 firstPage: true, 191 } 192} 193 194// HasMorePages returns a boolean indicating whether more pages are available 195func (p *ListTapesPaginator) HasMorePages() bool { 196 return p.firstPage || p.nextToken != nil 197} 198 199// NextPage retrieves the next ListTapes page. 200func (p *ListTapesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTapesOutput, error) { 201 if !p.HasMorePages() { 202 return nil, fmt.Errorf("no more pages available") 203 } 204 205 params := *p.params 206 params.Marker = p.nextToken 207 208 var limit *int32 209 if p.options.Limit > 0 { 210 limit = &p.options.Limit 211 } 212 params.Limit = limit 213 214 result, err := p.client.ListTapes(ctx, ¶ms, optFns...) 215 if err != nil { 216 return nil, err 217 } 218 p.firstPage = false 219 220 prevToken := p.nextToken 221 p.nextToken = result.Marker 222 223 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 224 p.nextToken = nil 225 } 226 227 return result, nil 228} 229 230func newServiceMetadataMiddleware_opListTapes(region string) *awsmiddleware.RegisterServiceMetadata { 231 return &awsmiddleware.RegisterServiceMetadata{ 232 Region: region, 233 ServiceID: ServiceID, 234 SigningName: "storagegateway", 235 OperationName: "ListTapes", 236 } 237} 238