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 entitlements that have been granted to this account. This 16// request returns 20 results per page. 17func (c *Client) ListEntitlements(ctx context.Context, params *ListEntitlementsInput, optFns ...func(*Options)) (*ListEntitlementsOutput, error) { 18 if params == nil { 19 params = &ListEntitlementsInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListEntitlements", params, optFns, addOperationListEntitlementsMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListEntitlementsOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type ListEntitlementsInput struct { 33 34 // The maximum number of results to return per API request. For example, you submit 35 // a ListEntitlements request with MaxResults set at 5. Although 20 items match 36 // your request, the service returns no more than the first 5 items. (The service 37 // also returns a NextToken value that you can use to fetch the next batch of 38 // results.) The service might return fewer results than the MaxResults value. If 39 // MaxResults is not included in the request, the service defaults to pagination 40 // with a maximum of 20 results per page. 41 MaxResults int32 42 43 // The token that identifies which batch of results that you want to see. For 44 // example, you submit a ListEntitlements request with MaxResults set at 5. The 45 // service returns the first batch of results (up to 5) and a NextToken value. To 46 // see the next batch of results, you can submit the ListEntitlements request a 47 // second time and specify the NextToken value. 48 NextToken *string 49} 50 51type ListEntitlementsOutput struct { 52 53 // A list of entitlements that have been granted to you from other AWS accounts. 54 Entitlements []types.ListedEntitlement 55 56 // The token that identifies which batch of results that you want to see. For 57 // example, you submit a ListEntitlements request with MaxResults set at 5. The 58 // service returns the first batch of results (up to 5) and a NextToken value. To 59 // see the next batch of results, you can submit the ListEntitlements request a 60 // second time and specify the NextToken value. 61 NextToken *string 62 63 // Metadata pertaining to the operation's result. 64 ResultMetadata middleware.Metadata 65} 66 67func addOperationListEntitlementsMiddlewares(stack *middleware.Stack, options Options) (err error) { 68 err = stack.Serialize.Add(&awsRestjson1_serializeOpListEntitlements{}, middleware.After) 69 if err != nil { 70 return err 71 } 72 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListEntitlements{}, middleware.After) 73 if err != nil { 74 return err 75 } 76 if err = addSetLoggerMiddleware(stack, options); err != nil { 77 return err 78 } 79 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 80 return err 81 } 82 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 83 return err 84 } 85 if err = addResolveEndpointMiddleware(stack, options); err != nil { 86 return err 87 } 88 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 89 return err 90 } 91 if err = addRetryMiddlewares(stack, options); err != nil { 92 return err 93 } 94 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 95 return err 96 } 97 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 98 return err 99 } 100 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 101 return err 102 } 103 if err = addClientUserAgent(stack); err != nil { 104 return err 105 } 106 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 107 return err 108 } 109 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 110 return err 111 } 112 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListEntitlements(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// ListEntitlementsAPIClient is a client that implements the ListEntitlements 128// operation. 129type ListEntitlementsAPIClient interface { 130 ListEntitlements(context.Context, *ListEntitlementsInput, ...func(*Options)) (*ListEntitlementsOutput, error) 131} 132 133var _ ListEntitlementsAPIClient = (*Client)(nil) 134 135// ListEntitlementsPaginatorOptions is the paginator options for ListEntitlements 136type ListEntitlementsPaginatorOptions struct { 137 // The maximum number of results to return per API request. For example, you submit 138 // a ListEntitlements request with MaxResults set at 5. Although 20 items match 139 // your request, the service returns no more than the first 5 items. (The service 140 // also returns a NextToken value that you can use to fetch the next batch of 141 // results.) The service might return fewer results than the MaxResults value. If 142 // MaxResults is not included in the request, the service defaults to pagination 143 // with a maximum of 20 results per page. 144 Limit int32 145 146 // Set to true if pagination should stop if the service returns a pagination token 147 // that matches the most recent token provided to the service. 148 StopOnDuplicateToken bool 149} 150 151// ListEntitlementsPaginator is a paginator for ListEntitlements 152type ListEntitlementsPaginator struct { 153 options ListEntitlementsPaginatorOptions 154 client ListEntitlementsAPIClient 155 params *ListEntitlementsInput 156 nextToken *string 157 firstPage bool 158} 159 160// NewListEntitlementsPaginator returns a new ListEntitlementsPaginator 161func NewListEntitlementsPaginator(client ListEntitlementsAPIClient, params *ListEntitlementsInput, optFns ...func(*ListEntitlementsPaginatorOptions)) *ListEntitlementsPaginator { 162 if params == nil { 163 params = &ListEntitlementsInput{} 164 } 165 166 options := ListEntitlementsPaginatorOptions{} 167 if params.MaxResults != 0 { 168 options.Limit = params.MaxResults 169 } 170 171 for _, fn := range optFns { 172 fn(&options) 173 } 174 175 return &ListEntitlementsPaginator{ 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 *ListEntitlementsPaginator) HasMorePages() bool { 185 return p.firstPage || p.nextToken != nil 186} 187 188// NextPage retrieves the next ListEntitlements page. 189func (p *ListEntitlementsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListEntitlementsOutput, error) { 190 if !p.HasMorePages() { 191 return nil, fmt.Errorf("no more pages available") 192 } 193 194 params := *p.params 195 params.NextToken = p.nextToken 196 197 params.MaxResults = p.options.Limit 198 199 result, err := p.client.ListEntitlements(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.NextToken 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_opListEntitlements(region string) *awsmiddleware.RegisterServiceMetadata { 216 return &awsmiddleware.RegisterServiceMetadata{ 217 Region: region, 218 ServiceID: ServiceID, 219 SigningName: "mediaconnect", 220 OperationName: "ListEntitlements", 221 } 222} 223