1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package mediaconvert 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/mediaconvert/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Retrieve a JSON array of up to twenty of your presets. This will return the 16// presets themselves, not just a list of them. To retrieve the next twenty 17// presets, use the nextToken string returned with the array. 18func (c *Client) ListPresets(ctx context.Context, params *ListPresetsInput, optFns ...func(*Options)) (*ListPresetsOutput, error) { 19 if params == nil { 20 params = &ListPresetsInput{} 21 } 22 23 result, metadata, err := c.invokeOperation(ctx, "ListPresets", params, optFns, addOperationListPresetsMiddlewares) 24 if err != nil { 25 return nil, err 26 } 27 28 out := result.(*ListPresetsOutput) 29 out.ResultMetadata = metadata 30 return out, nil 31} 32 33type ListPresetsInput struct { 34 35 // Optionally, specify a preset category to limit responses to only presets from 36 // that category. 37 Category *string 38 39 // Optional. When you request a list of presets, you can choose to list them 40 // alphabetically by NAME or chronologically by CREATION_DATE. If you don't 41 // specify, the service will list them by name. 42 ListBy types.PresetListBy 43 44 // Optional. Number of presets, up to twenty, that will be returned at one time 45 MaxResults int32 46 47 // Use this string, provided with the response to a previous request, to request 48 // the next batch of presets. 49 NextToken *string 50 51 // Optional. When you request lists of resources, you can specify whether they are 52 // sorted in ASCENDING or DESCENDING order. Default varies by resource. 53 Order types.Order 54} 55 56type ListPresetsOutput struct { 57 58 // Use this string to request the next batch of presets. 59 NextToken *string 60 61 // List of presets 62 Presets []types.Preset 63 64 // Metadata pertaining to the operation's result. 65 ResultMetadata middleware.Metadata 66} 67 68func addOperationListPresetsMiddlewares(stack *middleware.Stack, options Options) (err error) { 69 err = stack.Serialize.Add(&awsRestjson1_serializeOpListPresets{}, middleware.After) 70 if err != nil { 71 return err 72 } 73 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListPresets{}, 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 = stack.Initialize.Add(newServiceMetadataMiddleware_opListPresets(options.Region), middleware.Before); err != nil { 114 return err 115 } 116 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 117 return err 118 } 119 if err = addResponseErrorMiddleware(stack); err != nil { 120 return err 121 } 122 if err = addRequestResponseLogging(stack, options); err != nil { 123 return err 124 } 125 return nil 126} 127 128// ListPresetsAPIClient is a client that implements the ListPresets operation. 129type ListPresetsAPIClient interface { 130 ListPresets(context.Context, *ListPresetsInput, ...func(*Options)) (*ListPresetsOutput, error) 131} 132 133var _ ListPresetsAPIClient = (*Client)(nil) 134 135// ListPresetsPaginatorOptions is the paginator options for ListPresets 136type ListPresetsPaginatorOptions struct { 137 // Optional. Number of presets, up to twenty, that will be returned at one time 138 Limit int32 139 140 // Set to true if pagination should stop if the service returns a pagination token 141 // that matches the most recent token provided to the service. 142 StopOnDuplicateToken bool 143} 144 145// ListPresetsPaginator is a paginator for ListPresets 146type ListPresetsPaginator struct { 147 options ListPresetsPaginatorOptions 148 client ListPresetsAPIClient 149 params *ListPresetsInput 150 nextToken *string 151 firstPage bool 152} 153 154// NewListPresetsPaginator returns a new ListPresetsPaginator 155func NewListPresetsPaginator(client ListPresetsAPIClient, params *ListPresetsInput, optFns ...func(*ListPresetsPaginatorOptions)) *ListPresetsPaginator { 156 if params == nil { 157 params = &ListPresetsInput{} 158 } 159 160 options := ListPresetsPaginatorOptions{} 161 if params.MaxResults != 0 { 162 options.Limit = params.MaxResults 163 } 164 165 for _, fn := range optFns { 166 fn(&options) 167 } 168 169 return &ListPresetsPaginator{ 170 options: options, 171 client: client, 172 params: params, 173 firstPage: true, 174 } 175} 176 177// HasMorePages returns a boolean indicating whether more pages are available 178func (p *ListPresetsPaginator) HasMorePages() bool { 179 return p.firstPage || p.nextToken != nil 180} 181 182// NextPage retrieves the next ListPresets page. 183func (p *ListPresetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPresetsOutput, error) { 184 if !p.HasMorePages() { 185 return nil, fmt.Errorf("no more pages available") 186 } 187 188 params := *p.params 189 params.NextToken = p.nextToken 190 191 params.MaxResults = p.options.Limit 192 193 result, err := p.client.ListPresets(ctx, ¶ms, optFns...) 194 if err != nil { 195 return nil, err 196 } 197 p.firstPage = false 198 199 prevToken := p.nextToken 200 p.nextToken = result.NextToken 201 202 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 203 p.nextToken = nil 204 } 205 206 return result, nil 207} 208 209func newServiceMetadataMiddleware_opListPresets(region string) *awsmiddleware.RegisterServiceMetadata { 210 return &awsmiddleware.RegisterServiceMetadata{ 211 Region: region, 212 ServiceID: ServiceID, 213 SigningName: "mediaconvert", 214 OperationName: "ListPresets", 215 } 216} 217