1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package connect 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/connect/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// This API is in preview release for Amazon Connect and is subject to change. 16// Return a list of instances which are in active state, creation-in-progress 17// state, and failed state. Instances that aren't successfully created (they are in 18// a failed state) are returned only for 24 hours after the CreateInstance API was 19// invoked. 20func (c *Client) ListInstances(ctx context.Context, params *ListInstancesInput, optFns ...func(*Options)) (*ListInstancesOutput, error) { 21 if params == nil { 22 params = &ListInstancesInput{} 23 } 24 25 result, metadata, err := c.invokeOperation(ctx, "ListInstances", params, optFns, addOperationListInstancesMiddlewares) 26 if err != nil { 27 return nil, err 28 } 29 30 out := result.(*ListInstancesOutput) 31 out.ResultMetadata = metadata 32 return out, nil 33} 34 35type ListInstancesInput struct { 36 37 // The maximum number of results to return per page. 38 MaxResults int32 39 40 // The token for the next set of results. Use the value returned in the previous 41 // response in the next request to retrieve the next set of results. 42 NextToken *string 43} 44 45type ListInstancesOutput struct { 46 47 // Information about the instances. 48 InstanceSummaryList []types.InstanceSummary 49 50 // If there are additional results, this is the token for the next set of results. 51 NextToken *string 52 53 // Metadata pertaining to the operation's result. 54 ResultMetadata middleware.Metadata 55} 56 57func addOperationListInstancesMiddlewares(stack *middleware.Stack, options Options) (err error) { 58 err = stack.Serialize.Add(&awsRestjson1_serializeOpListInstances{}, middleware.After) 59 if err != nil { 60 return err 61 } 62 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListInstances{}, middleware.After) 63 if err != nil { 64 return err 65 } 66 if err = addSetLoggerMiddleware(stack, options); err != nil { 67 return err 68 } 69 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 70 return err 71 } 72 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 73 return err 74 } 75 if err = addResolveEndpointMiddleware(stack, options); err != nil { 76 return err 77 } 78 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 79 return err 80 } 81 if err = addRetryMiddlewares(stack, options); err != nil { 82 return err 83 } 84 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 85 return err 86 } 87 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 88 return err 89 } 90 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 91 return err 92 } 93 if err = addClientUserAgent(stack); err != nil { 94 return err 95 } 96 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 97 return err 98 } 99 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 100 return err 101 } 102 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListInstances(options.Region), middleware.Before); err != nil { 103 return err 104 } 105 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 106 return err 107 } 108 if err = addResponseErrorMiddleware(stack); err != nil { 109 return err 110 } 111 if err = addRequestResponseLogging(stack, options); err != nil { 112 return err 113 } 114 return nil 115} 116 117// ListInstancesAPIClient is a client that implements the ListInstances operation. 118type ListInstancesAPIClient interface { 119 ListInstances(context.Context, *ListInstancesInput, ...func(*Options)) (*ListInstancesOutput, error) 120} 121 122var _ ListInstancesAPIClient = (*Client)(nil) 123 124// ListInstancesPaginatorOptions is the paginator options for ListInstances 125type ListInstancesPaginatorOptions struct { 126 // The maximum number of results to return per page. 127 Limit int32 128 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// ListInstancesPaginator is a paginator for ListInstances 135type ListInstancesPaginator struct { 136 options ListInstancesPaginatorOptions 137 client ListInstancesAPIClient 138 params *ListInstancesInput 139 nextToken *string 140 firstPage bool 141} 142 143// NewListInstancesPaginator returns a new ListInstancesPaginator 144func NewListInstancesPaginator(client ListInstancesAPIClient, params *ListInstancesInput, optFns ...func(*ListInstancesPaginatorOptions)) *ListInstancesPaginator { 145 if params == nil { 146 params = &ListInstancesInput{} 147 } 148 149 options := ListInstancesPaginatorOptions{} 150 if params.MaxResults != 0 { 151 options.Limit = params.MaxResults 152 } 153 154 for _, fn := range optFns { 155 fn(&options) 156 } 157 158 return &ListInstancesPaginator{ 159 options: options, 160 client: client, 161 params: params, 162 firstPage: true, 163 } 164} 165 166// HasMorePages returns a boolean indicating whether more pages are available 167func (p *ListInstancesPaginator) HasMorePages() bool { 168 return p.firstPage || p.nextToken != nil 169} 170 171// NextPage retrieves the next ListInstances page. 172func (p *ListInstancesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListInstancesOutput, error) { 173 if !p.HasMorePages() { 174 return nil, fmt.Errorf("no more pages available") 175 } 176 177 params := *p.params 178 params.NextToken = p.nextToken 179 180 params.MaxResults = p.options.Limit 181 182 result, err := p.client.ListInstances(ctx, ¶ms, optFns...) 183 if err != nil { 184 return nil, err 185 } 186 p.firstPage = false 187 188 prevToken := p.nextToken 189 p.nextToken = result.NextToken 190 191 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 192 p.nextToken = nil 193 } 194 195 return result, nil 196} 197 198func newServiceMetadataMiddleware_opListInstances(region string) *awsmiddleware.RegisterServiceMetadata { 199 return &awsmiddleware.RegisterServiceMetadata{ 200 Region: region, 201 ServiceID: ServiceID, 202 SigningName: "connect", 203 OperationName: "ListInstances", 204 } 205} 206