1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package elastictranscoder 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/elastictranscoder/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// The ListPresets operation gets a list of the default presets included with 16// Elastic Transcoder and the presets that you've added in an AWS region. 17func (c *Client) ListPresets(ctx context.Context, params *ListPresetsInput, optFns ...func(*Options)) (*ListPresetsOutput, error) { 18 if params == nil { 19 params = &ListPresetsInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListPresets", params, optFns, addOperationListPresetsMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListPresetsOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32// The ListPresetsRequest structure. 33type ListPresetsInput struct { 34 35 // To list presets in chronological order by the date and time that they were 36 // created, enter true. To list presets in reverse chronological order, enter 37 // false. 38 Ascending *string 39 40 // When Elastic Transcoder returns more than one page of results, use pageToken in 41 // subsequent GET requests to get each successive page of results. 42 PageToken *string 43} 44 45// The ListPresetsResponse structure. 46type ListPresetsOutput struct { 47 48 // A value that you use to access the second and subsequent pages of results, if 49 // any. When the presets fit on one page or when you've reached the last page of 50 // results, the value of NextPageToken is null. 51 NextPageToken *string 52 53 // An array of Preset objects. 54 Presets []types.Preset 55 56 // Metadata pertaining to the operation's result. 57 ResultMetadata middleware.Metadata 58} 59 60func addOperationListPresetsMiddlewares(stack *middleware.Stack, options Options) (err error) { 61 err = stack.Serialize.Add(&awsRestjson1_serializeOpListPresets{}, middleware.After) 62 if err != nil { 63 return err 64 } 65 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListPresets{}, middleware.After) 66 if err != nil { 67 return err 68 } 69 if err = addSetLoggerMiddleware(stack, options); err != nil { 70 return err 71 } 72 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 73 return err 74 } 75 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 76 return err 77 } 78 if err = addResolveEndpointMiddleware(stack, options); err != nil { 79 return err 80 } 81 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 82 return err 83 } 84 if err = addRetryMiddlewares(stack, options); err != nil { 85 return err 86 } 87 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 88 return err 89 } 90 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 91 return err 92 } 93 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 94 return err 95 } 96 if err = addClientUserAgent(stack); err != nil { 97 return err 98 } 99 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 100 return err 101 } 102 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 103 return err 104 } 105 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPresets(options.Region), middleware.Before); err != nil { 106 return err 107 } 108 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 109 return err 110 } 111 if err = addResponseErrorMiddleware(stack); err != nil { 112 return err 113 } 114 if err = addRequestResponseLogging(stack, options); err != nil { 115 return err 116 } 117 return nil 118} 119 120// ListPresetsAPIClient is a client that implements the ListPresets operation. 121type ListPresetsAPIClient interface { 122 ListPresets(context.Context, *ListPresetsInput, ...func(*Options)) (*ListPresetsOutput, error) 123} 124 125var _ ListPresetsAPIClient = (*Client)(nil) 126 127// ListPresetsPaginatorOptions is the paginator options for ListPresets 128type ListPresetsPaginatorOptions struct { 129 // Set to true if pagination should stop if the service returns a pagination token 130 // that matches the most recent token provided to the service. 131 StopOnDuplicateToken bool 132} 133 134// ListPresetsPaginator is a paginator for ListPresets 135type ListPresetsPaginator struct { 136 options ListPresetsPaginatorOptions 137 client ListPresetsAPIClient 138 params *ListPresetsInput 139 nextToken *string 140 firstPage bool 141} 142 143// NewListPresetsPaginator returns a new ListPresetsPaginator 144func NewListPresetsPaginator(client ListPresetsAPIClient, params *ListPresetsInput, optFns ...func(*ListPresetsPaginatorOptions)) *ListPresetsPaginator { 145 if params == nil { 146 params = &ListPresetsInput{} 147 } 148 149 options := ListPresetsPaginatorOptions{} 150 151 for _, fn := range optFns { 152 fn(&options) 153 } 154 155 return &ListPresetsPaginator{ 156 options: options, 157 client: client, 158 params: params, 159 firstPage: true, 160 } 161} 162 163// HasMorePages returns a boolean indicating whether more pages are available 164func (p *ListPresetsPaginator) HasMorePages() bool { 165 return p.firstPage || p.nextToken != nil 166} 167 168// NextPage retrieves the next ListPresets page. 169func (p *ListPresetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPresetsOutput, error) { 170 if !p.HasMorePages() { 171 return nil, fmt.Errorf("no more pages available") 172 } 173 174 params := *p.params 175 params.PageToken = p.nextToken 176 177 result, err := p.client.ListPresets(ctx, ¶ms, optFns...) 178 if err != nil { 179 return nil, err 180 } 181 p.firstPage = false 182 183 prevToken := p.nextToken 184 p.nextToken = result.NextPageToken 185 186 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 187 p.nextToken = nil 188 } 189 190 return result, nil 191} 192 193func newServiceMetadataMiddleware_opListPresets(region string) *awsmiddleware.RegisterServiceMetadata { 194 return &awsmiddleware.RegisterServiceMetadata{ 195 Region: region, 196 ServiceID: ServiceID, 197 SigningName: "elastictranscoder", 198 OperationName: "ListPresets", 199 } 200} 201