1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package servicecatalog 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/servicecatalog/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists all portfolios that the specified product is associated with. 16func (c *Client) ListPortfoliosForProduct(ctx context.Context, params *ListPortfoliosForProductInput, optFns ...func(*Options)) (*ListPortfoliosForProductOutput, error) { 17 if params == nil { 18 params = &ListPortfoliosForProductInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListPortfoliosForProduct", params, optFns, addOperationListPortfoliosForProductMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListPortfoliosForProductOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListPortfoliosForProductInput struct { 32 33 // The product identifier. 34 // 35 // This member is required. 36 ProductId *string 37 38 // The language code. 39 // 40 // * en - English (default) 41 // 42 // * jp - Japanese 43 // 44 // * zh - Chinese 45 AcceptLanguage *string 46 47 // The maximum number of items to return with this call. 48 PageSize int32 49 50 // The page token for the next set of results. To retrieve the first set of 51 // results, use null. 52 PageToken *string 53} 54 55type ListPortfoliosForProductOutput struct { 56 57 // The page token to use to retrieve the next set of results. If there are no 58 // additional results, this value is null. 59 NextPageToken *string 60 61 // Information about the portfolios. 62 PortfolioDetails []types.PortfolioDetail 63 64 // Metadata pertaining to the operation's result. 65 ResultMetadata middleware.Metadata 66} 67 68func addOperationListPortfoliosForProductMiddlewares(stack *middleware.Stack, options Options) (err error) { 69 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListPortfoliosForProduct{}, middleware.After) 70 if err != nil { 71 return err 72 } 73 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListPortfoliosForProduct{}, middleware.After) 74 if err != nil { 75 return err 76 } 77 if err = addSetLoggerMiddleware(stack, options); err != nil { 78 return err 79 } 80 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 81 return err 82 } 83 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 84 return err 85 } 86 if err = addResolveEndpointMiddleware(stack, options); err != nil { 87 return err 88 } 89 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 90 return err 91 } 92 if err = addRetryMiddlewares(stack, options); err != nil { 93 return err 94 } 95 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 96 return err 97 } 98 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 99 return err 100 } 101 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 102 return err 103 } 104 if err = addClientUserAgent(stack); err != nil { 105 return err 106 } 107 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 108 return err 109 } 110 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 111 return err 112 } 113 if err = addOpListPortfoliosForProductValidationMiddleware(stack); err != nil { 114 return err 115 } 116 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPortfoliosForProduct(options.Region), middleware.Before); err != nil { 117 return err 118 } 119 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 120 return err 121 } 122 if err = addResponseErrorMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addRequestResponseLogging(stack, options); err != nil { 126 return err 127 } 128 return nil 129} 130 131// ListPortfoliosForProductAPIClient is a client that implements the 132// ListPortfoliosForProduct operation. 133type ListPortfoliosForProductAPIClient interface { 134 ListPortfoliosForProduct(context.Context, *ListPortfoliosForProductInput, ...func(*Options)) (*ListPortfoliosForProductOutput, error) 135} 136 137var _ ListPortfoliosForProductAPIClient = (*Client)(nil) 138 139// ListPortfoliosForProductPaginatorOptions is the paginator options for 140// ListPortfoliosForProduct 141type ListPortfoliosForProductPaginatorOptions struct { 142 // The maximum number of items to return with this call. 143 Limit int32 144 145 // Set to true if pagination should stop if the service returns a pagination token 146 // that matches the most recent token provided to the service. 147 StopOnDuplicateToken bool 148} 149 150// ListPortfoliosForProductPaginator is a paginator for ListPortfoliosForProduct 151type ListPortfoliosForProductPaginator struct { 152 options ListPortfoliosForProductPaginatorOptions 153 client ListPortfoliosForProductAPIClient 154 params *ListPortfoliosForProductInput 155 nextToken *string 156 firstPage bool 157} 158 159// NewListPortfoliosForProductPaginator returns a new 160// ListPortfoliosForProductPaginator 161func NewListPortfoliosForProductPaginator(client ListPortfoliosForProductAPIClient, params *ListPortfoliosForProductInput, optFns ...func(*ListPortfoliosForProductPaginatorOptions)) *ListPortfoliosForProductPaginator { 162 options := ListPortfoliosForProductPaginatorOptions{} 163 if params.PageSize != 0 { 164 options.Limit = params.PageSize 165 } 166 167 for _, fn := range optFns { 168 fn(&options) 169 } 170 171 if params == nil { 172 params = &ListPortfoliosForProductInput{} 173 } 174 175 return &ListPortfoliosForProductPaginator{ 176 options: options, 177 client: client, 178 params: params, 179 firstPage: true, 180 } 181} 182 183// HasMorePages returns a boolean indicating whether more pages are available 184func (p *ListPortfoliosForProductPaginator) HasMorePages() bool { 185 return p.firstPage || p.nextToken != nil 186} 187 188// NextPage retrieves the next ListPortfoliosForProduct page. 189func (p *ListPortfoliosForProductPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPortfoliosForProductOutput, error) { 190 if !p.HasMorePages() { 191 return nil, fmt.Errorf("no more pages available") 192 } 193 194 params := *p.params 195 params.PageToken = p.nextToken 196 197 params.PageSize = p.options.Limit 198 199 result, err := p.client.ListPortfoliosForProduct(ctx, ¶ms, optFns...) 200 if err != nil { 201 return nil, err 202 } 203 p.firstPage = false 204 205 prevToken := p.nextToken 206 p.nextToken = result.NextPageToken 207 208 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 209 p.nextToken = nil 210 } 211 212 return result, nil 213} 214 215func newServiceMetadataMiddleware_opListPortfoliosForProduct(region string) *awsmiddleware.RegisterServiceMetadata { 216 return &awsmiddleware.RegisterServiceMetadata{ 217 Region: region, 218 ServiceID: ServiceID, 219 SigningName: "servicecatalog", 220 OperationName: "ListPortfoliosForProduct", 221 } 222} 223