1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package mediaconnect 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/mediaconnect/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Displays a list of all reservations that have been purchased by this account in 16// the current AWS Region. This list includes all reservations in all states (such 17// as active and expired). 18func (c *Client) ListReservations(ctx context.Context, params *ListReservationsInput, optFns ...func(*Options)) (*ListReservationsOutput, error) { 19 if params == nil { 20 params = &ListReservationsInput{} 21 } 22 23 result, metadata, err := c.invokeOperation(ctx, "ListReservations", params, optFns, addOperationListReservationsMiddlewares) 24 if err != nil { 25 return nil, err 26 } 27 28 out := result.(*ListReservationsOutput) 29 out.ResultMetadata = metadata 30 return out, nil 31} 32 33type ListReservationsInput struct { 34 35 // The maximum number of results to return per API request. For example, you submit 36 // a ListReservations request with MaxResults set at 5. Although 20 items match 37 // your request, the service returns no more than the first 5 items. (The service 38 // also returns a NextToken value that you can use to fetch the next batch of 39 // results.) The service might return fewer results than the MaxResults value. If 40 // MaxResults is not included in the request, the service defaults to pagination 41 // with a maximum of 10 results per page. 42 MaxResults int32 43 44 // The token that identifies which batch of results that you want to see. For 45 // example, you submit a ListReservations request with MaxResults set at 5. The 46 // service returns the first batch of results (up to 5) and a NextToken value. To 47 // see the next batch of results, you can submit the ListOfferings request a second 48 // time and specify the NextToken value. 49 NextToken *string 50} 51 52type ListReservationsOutput struct { 53 54 // The token that identifies which batch of results that you want to see. For 55 // example, you submit a ListReservations request with MaxResults set at 5. The 56 // service returns the first batch of results (up to 5) and a NextToken value. To 57 // see the next batch of results, you can submit the ListReservations request a 58 // second time and specify the NextToken value. 59 NextToken *string 60 61 // A list of all reservations that have been purchased by this account in the 62 // current AWS Region. 63 Reservations []types.Reservation 64 65 // Metadata pertaining to the operation's result. 66 ResultMetadata middleware.Metadata 67} 68 69func addOperationListReservationsMiddlewares(stack *middleware.Stack, options Options) (err error) { 70 err = stack.Serialize.Add(&awsRestjson1_serializeOpListReservations{}, middleware.After) 71 if err != nil { 72 return err 73 } 74 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListReservations{}, middleware.After) 75 if err != nil { 76 return err 77 } 78 if err = addSetLoggerMiddleware(stack, options); err != nil { 79 return err 80 } 81 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 82 return err 83 } 84 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 85 return err 86 } 87 if err = addResolveEndpointMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 91 return err 92 } 93 if err = addRetryMiddlewares(stack, options); err != nil { 94 return err 95 } 96 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 97 return err 98 } 99 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 100 return err 101 } 102 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 103 return err 104 } 105 if err = addClientUserAgent(stack); err != nil { 106 return err 107 } 108 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 109 return err 110 } 111 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 112 return err 113 } 114 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListReservations(options.Region), middleware.Before); err != nil { 115 return err 116 } 117 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 118 return err 119 } 120 if err = addResponseErrorMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addRequestResponseLogging(stack, options); err != nil { 124 return err 125 } 126 return nil 127} 128 129// ListReservationsAPIClient is a client that implements the ListReservations 130// operation. 131type ListReservationsAPIClient interface { 132 ListReservations(context.Context, *ListReservationsInput, ...func(*Options)) (*ListReservationsOutput, error) 133} 134 135var _ ListReservationsAPIClient = (*Client)(nil) 136 137// ListReservationsPaginatorOptions is the paginator options for ListReservations 138type ListReservationsPaginatorOptions struct { 139 // The maximum number of results to return per API request. For example, you submit 140 // a ListReservations request with MaxResults set at 5. Although 20 items match 141 // your request, the service returns no more than the first 5 items. (The service 142 // also returns a NextToken value that you can use to fetch the next batch of 143 // results.) The service might return fewer results than the MaxResults value. If 144 // MaxResults is not included in the request, the service defaults to pagination 145 // with a maximum of 10 results per page. 146 Limit int32 147 148 // Set to true if pagination should stop if the service returns a pagination token 149 // that matches the most recent token provided to the service. 150 StopOnDuplicateToken bool 151} 152 153// ListReservationsPaginator is a paginator for ListReservations 154type ListReservationsPaginator struct { 155 options ListReservationsPaginatorOptions 156 client ListReservationsAPIClient 157 params *ListReservationsInput 158 nextToken *string 159 firstPage bool 160} 161 162// NewListReservationsPaginator returns a new ListReservationsPaginator 163func NewListReservationsPaginator(client ListReservationsAPIClient, params *ListReservationsInput, optFns ...func(*ListReservationsPaginatorOptions)) *ListReservationsPaginator { 164 if params == nil { 165 params = &ListReservationsInput{} 166 } 167 168 options := ListReservationsPaginatorOptions{} 169 if params.MaxResults != 0 { 170 options.Limit = params.MaxResults 171 } 172 173 for _, fn := range optFns { 174 fn(&options) 175 } 176 177 return &ListReservationsPaginator{ 178 options: options, 179 client: client, 180 params: params, 181 firstPage: true, 182 } 183} 184 185// HasMorePages returns a boolean indicating whether more pages are available 186func (p *ListReservationsPaginator) HasMorePages() bool { 187 return p.firstPage || p.nextToken != nil 188} 189 190// NextPage retrieves the next ListReservations page. 191func (p *ListReservationsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListReservationsOutput, error) { 192 if !p.HasMorePages() { 193 return nil, fmt.Errorf("no more pages available") 194 } 195 196 params := *p.params 197 params.NextToken = p.nextToken 198 199 params.MaxResults = p.options.Limit 200 201 result, err := p.client.ListReservations(ctx, ¶ms, optFns...) 202 if err != nil { 203 return nil, err 204 } 205 p.firstPage = false 206 207 prevToken := p.nextToken 208 p.nextToken = result.NextToken 209 210 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 211 p.nextToken = nil 212 } 213 214 return result, nil 215} 216 217func newServiceMetadataMiddleware_opListReservations(region string) *awsmiddleware.RegisterServiceMetadata { 218 return &awsmiddleware.RegisterServiceMetadata{ 219 Region: region, 220 ServiceID: ServiceID, 221 SigningName: "mediaconnect", 222 OperationName: "ListReservations", 223 } 224} 225