1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package ec2 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/ec2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of all instance types offered. The results can be filtered by 16// location (Region or Availability Zone). If no location is specified, the 17// instance types offered in the current Region are returned. 18func (c *Client) DescribeInstanceTypeOfferings(ctx context.Context, params *DescribeInstanceTypeOfferingsInput, optFns ...func(*Options)) (*DescribeInstanceTypeOfferingsOutput, error) { 19 if params == nil { 20 params = &DescribeInstanceTypeOfferingsInput{} 21 } 22 23 result, metadata, err := c.invokeOperation(ctx, "DescribeInstanceTypeOfferings", params, optFns, addOperationDescribeInstanceTypeOfferingsMiddlewares) 24 if err != nil { 25 return nil, err 26 } 27 28 out := result.(*DescribeInstanceTypeOfferingsOutput) 29 out.ResultMetadata = metadata 30 return out, nil 31} 32 33type DescribeInstanceTypeOfferingsInput struct { 34 35 // Checks whether you have the required permissions for the action, without 36 // actually making the request, and provides an error response. If you have the 37 // required permissions, the error response is DryRunOperation. Otherwise, it is 38 // UnauthorizedOperation. 39 DryRun bool 40 41 // One or more filters. Filter names and values are case-sensitive. 42 // 43 // * location - 44 // This depends on the location type. For example, if the location type is region 45 // (default), the location is the Region code (for example, us-east-2.) 46 // 47 // * 48 // instance-type - The instance type. For example, c5.2xlarge. 49 Filters []types.Filter 50 51 // The location type. 52 LocationType types.LocationType 53 54 // The maximum number of results to return for the request in a single page. The 55 // remaining results can be seen by sending another request with the next token 56 // value. 57 MaxResults *int32 58 59 // The token to retrieve the next page of results. 60 NextToken *string 61} 62 63type DescribeInstanceTypeOfferingsOutput struct { 64 65 // The instance types offered. 66 InstanceTypeOfferings []types.InstanceTypeOffering 67 68 // The token to use to retrieve the next page of results. This value is null when 69 // there are no more results to return. 70 NextToken *string 71 72 // Metadata pertaining to the operation's result. 73 ResultMetadata middleware.Metadata 74} 75 76func addOperationDescribeInstanceTypeOfferingsMiddlewares(stack *middleware.Stack, options Options) (err error) { 77 err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeInstanceTypeOfferings{}, middleware.After) 78 if err != nil { 79 return err 80 } 81 err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeInstanceTypeOfferings{}, middleware.After) 82 if err != nil { 83 return err 84 } 85 if err = addSetLoggerMiddleware(stack, options); err != nil { 86 return err 87 } 88 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 89 return err 90 } 91 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 92 return err 93 } 94 if err = addResolveEndpointMiddleware(stack, options); err != nil { 95 return err 96 } 97 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 98 return err 99 } 100 if err = addRetryMiddlewares(stack, options); err != nil { 101 return err 102 } 103 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 104 return err 105 } 106 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 107 return err 108 } 109 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 110 return err 111 } 112 if err = addClientUserAgent(stack); err != nil { 113 return err 114 } 115 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 116 return err 117 } 118 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 119 return err 120 } 121 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeInstanceTypeOfferings(options.Region), middleware.Before); err != nil { 122 return err 123 } 124 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 125 return err 126 } 127 if err = addResponseErrorMiddleware(stack); err != nil { 128 return err 129 } 130 if err = addRequestResponseLogging(stack, options); err != nil { 131 return err 132 } 133 return nil 134} 135 136// DescribeInstanceTypeOfferingsAPIClient is a client that implements the 137// DescribeInstanceTypeOfferings operation. 138type DescribeInstanceTypeOfferingsAPIClient interface { 139 DescribeInstanceTypeOfferings(context.Context, *DescribeInstanceTypeOfferingsInput, ...func(*Options)) (*DescribeInstanceTypeOfferingsOutput, error) 140} 141 142var _ DescribeInstanceTypeOfferingsAPIClient = (*Client)(nil) 143 144// DescribeInstanceTypeOfferingsPaginatorOptions is the paginator options for 145// DescribeInstanceTypeOfferings 146type DescribeInstanceTypeOfferingsPaginatorOptions struct { 147 // The maximum number of results to return for the request in a single page. The 148 // remaining results can be seen by sending another request with the next token 149 // value. 150 Limit int32 151 152 // Set to true if pagination should stop if the service returns a pagination token 153 // that matches the most recent token provided to the service. 154 StopOnDuplicateToken bool 155} 156 157// DescribeInstanceTypeOfferingsPaginator is a paginator for 158// DescribeInstanceTypeOfferings 159type DescribeInstanceTypeOfferingsPaginator struct { 160 options DescribeInstanceTypeOfferingsPaginatorOptions 161 client DescribeInstanceTypeOfferingsAPIClient 162 params *DescribeInstanceTypeOfferingsInput 163 nextToken *string 164 firstPage bool 165} 166 167// NewDescribeInstanceTypeOfferingsPaginator returns a new 168// DescribeInstanceTypeOfferingsPaginator 169func NewDescribeInstanceTypeOfferingsPaginator(client DescribeInstanceTypeOfferingsAPIClient, params *DescribeInstanceTypeOfferingsInput, optFns ...func(*DescribeInstanceTypeOfferingsPaginatorOptions)) *DescribeInstanceTypeOfferingsPaginator { 170 options := DescribeInstanceTypeOfferingsPaginatorOptions{} 171 if params.MaxResults != nil { 172 options.Limit = *params.MaxResults 173 } 174 175 for _, fn := range optFns { 176 fn(&options) 177 } 178 179 if params == nil { 180 params = &DescribeInstanceTypeOfferingsInput{} 181 } 182 183 return &DescribeInstanceTypeOfferingsPaginator{ 184 options: options, 185 client: client, 186 params: params, 187 firstPage: true, 188 } 189} 190 191// HasMorePages returns a boolean indicating whether more pages are available 192func (p *DescribeInstanceTypeOfferingsPaginator) HasMorePages() bool { 193 return p.firstPage || p.nextToken != nil 194} 195 196// NextPage retrieves the next DescribeInstanceTypeOfferings page. 197func (p *DescribeInstanceTypeOfferingsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeInstanceTypeOfferingsOutput, error) { 198 if !p.HasMorePages() { 199 return nil, fmt.Errorf("no more pages available") 200 } 201 202 params := *p.params 203 params.NextToken = p.nextToken 204 205 var limit *int32 206 if p.options.Limit > 0 { 207 limit = &p.options.Limit 208 } 209 params.MaxResults = limit 210 211 result, err := p.client.DescribeInstanceTypeOfferings(ctx, ¶ms, optFns...) 212 if err != nil { 213 return nil, err 214 } 215 p.firstPage = false 216 217 prevToken := p.nextToken 218 p.nextToken = result.NextToken 219 220 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 221 p.nextToken = nil 222 } 223 224 return result, nil 225} 226 227func newServiceMetadataMiddleware_opDescribeInstanceTypeOfferings(region string) *awsmiddleware.RegisterServiceMetadata { 228 return &awsmiddleware.RegisterServiceMetadata{ 229 Region: region, 230 ServiceID: ServiceID, 231 SigningName: "ec2", 232 OperationName: "DescribeInstanceTypeOfferings", 233 } 234} 235