1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package robomaker 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/robomaker/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists worlds. 16func (c *Client) ListWorlds(ctx context.Context, params *ListWorldsInput, optFns ...func(*Options)) (*ListWorldsOutput, error) { 17 if params == nil { 18 params = &ListWorldsInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListWorlds", params, optFns, c.addOperationListWorldsMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListWorldsOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListWorldsInput struct { 32 33 // Optional filters to limit results. You can use status. 34 Filters []types.Filter 35 36 // When this parameter is used, ListWorlds only returns maxResults results in a 37 // single page along with a nextToken response element. The remaining results of 38 // the initial request can be seen by sending another ListWorlds request with the 39 // returned nextToken value. This value can be between 1 and 100. If this parameter 40 // is not used, then ListWorlds returns up to 100 results and a nextToken value if 41 // applicable. 42 MaxResults *int32 43 44 // If the previous paginated request did not return all of the remaining results, 45 // the response object's nextToken parameter value is set to a token. To retrieve 46 // the next set of results, call ListWorlds again and assign that token to the 47 // request object's nextToken parameter. If there are no remaining results, the 48 // previous response object's NextToken parameter is set to null. 49 NextToken *string 50 51 noSmithyDocumentSerde 52} 53 54type ListWorldsOutput struct { 55 56 // If the previous paginated request did not return all of the remaining results, 57 // the response object's nextToken parameter value is set to a token. To retrieve 58 // the next set of results, call ListWorlds again and assign that token to the 59 // request object's nextToken parameter. If there are no remaining results, the 60 // previous response object's NextToken parameter is set to null. 61 NextToken *string 62 63 // Summary information for worlds. 64 WorldSummaries []types.WorldSummary 65 66 // Metadata pertaining to the operation's result. 67 ResultMetadata middleware.Metadata 68 69 noSmithyDocumentSerde 70} 71 72func (c *Client) addOperationListWorldsMiddlewares(stack *middleware.Stack, options Options) (err error) { 73 err = stack.Serialize.Add(&awsRestjson1_serializeOpListWorlds{}, middleware.After) 74 if err != nil { 75 return err 76 } 77 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListWorlds{}, middleware.After) 78 if err != nil { 79 return err 80 } 81 if err = addSetLoggerMiddleware(stack, options); err != nil { 82 return err 83 } 84 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 85 return err 86 } 87 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 88 return err 89 } 90 if err = addResolveEndpointMiddleware(stack, options); err != nil { 91 return err 92 } 93 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 94 return err 95 } 96 if err = addRetryMiddlewares(stack, options); err != nil { 97 return err 98 } 99 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 100 return err 101 } 102 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 103 return err 104 } 105 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 106 return err 107 } 108 if err = addClientUserAgent(stack); err != nil { 109 return err 110 } 111 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 112 return err 113 } 114 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 115 return err 116 } 117 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListWorlds(options.Region), middleware.Before); err != nil { 118 return err 119 } 120 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addResponseErrorMiddleware(stack); err != nil { 124 return err 125 } 126 if err = addRequestResponseLogging(stack, options); err != nil { 127 return err 128 } 129 return nil 130} 131 132// ListWorldsAPIClient is a client that implements the ListWorlds operation. 133type ListWorldsAPIClient interface { 134 ListWorlds(context.Context, *ListWorldsInput, ...func(*Options)) (*ListWorldsOutput, error) 135} 136 137var _ ListWorldsAPIClient = (*Client)(nil) 138 139// ListWorldsPaginatorOptions is the paginator options for ListWorlds 140type ListWorldsPaginatorOptions struct { 141 // When this parameter is used, ListWorlds only returns maxResults results in a 142 // single page along with a nextToken response element. The remaining results of 143 // the initial request can be seen by sending another ListWorlds request with the 144 // returned nextToken value. This value can be between 1 and 100. If this parameter 145 // is not used, then ListWorlds returns up to 100 results and a nextToken value if 146 // applicable. 147 Limit int32 148 149 // Set to true if pagination should stop if the service returns a pagination token 150 // that matches the most recent token provided to the service. 151 StopOnDuplicateToken bool 152} 153 154// ListWorldsPaginator is a paginator for ListWorlds 155type ListWorldsPaginator struct { 156 options ListWorldsPaginatorOptions 157 client ListWorldsAPIClient 158 params *ListWorldsInput 159 nextToken *string 160 firstPage bool 161} 162 163// NewListWorldsPaginator returns a new ListWorldsPaginator 164func NewListWorldsPaginator(client ListWorldsAPIClient, params *ListWorldsInput, optFns ...func(*ListWorldsPaginatorOptions)) *ListWorldsPaginator { 165 if params == nil { 166 params = &ListWorldsInput{} 167 } 168 169 options := ListWorldsPaginatorOptions{} 170 if params.MaxResults != nil { 171 options.Limit = *params.MaxResults 172 } 173 174 for _, fn := range optFns { 175 fn(&options) 176 } 177 178 return &ListWorldsPaginator{ 179 options: options, 180 client: client, 181 params: params, 182 firstPage: true, 183 } 184} 185 186// HasMorePages returns a boolean indicating whether more pages are available 187func (p *ListWorldsPaginator) HasMorePages() bool { 188 return p.firstPage || p.nextToken != nil 189} 190 191// NextPage retrieves the next ListWorlds page. 192func (p *ListWorldsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListWorldsOutput, error) { 193 if !p.HasMorePages() { 194 return nil, fmt.Errorf("no more pages available") 195 } 196 197 params := *p.params 198 params.NextToken = p.nextToken 199 200 var limit *int32 201 if p.options.Limit > 0 { 202 limit = &p.options.Limit 203 } 204 params.MaxResults = limit 205 206 result, err := p.client.ListWorlds(ctx, ¶ms, optFns...) 207 if err != nil { 208 return nil, err 209 } 210 p.firstPage = false 211 212 prevToken := p.nextToken 213 p.nextToken = result.NextToken 214 215 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 216 p.nextToken = nil 217 } 218 219 return result, nil 220} 221 222func newServiceMetadataMiddleware_opListWorlds(region string) *awsmiddleware.RegisterServiceMetadata { 223 return &awsmiddleware.RegisterServiceMetadata{ 224 Region: region, 225 ServiceID: ServiceID, 226 SigningName: "robomaker", 227 OperationName: "ListWorlds", 228 } 229} 230