1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package appmesh 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/appmesh/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of existing service meshes. 16func (c *Client) ListMeshes(ctx context.Context, params *ListMeshesInput, optFns ...func(*Options)) (*ListMeshesOutput, error) { 17 if params == nil { 18 params = &ListMeshesInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListMeshes", params, optFns, addOperationListMeshesMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListMeshesOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31// 32type ListMeshesInput struct { 33 34 // The maximum number of results returned by ListMeshes in paginated output. When 35 // you use this parameter, ListMeshes returns only limit results in a single page 36 // along with a nextToken response element. You can see the remaining results of 37 // the initial request by sending another ListMeshes request with the returned 38 // nextToken value. This value can be between 1 and 100. If you don't use this 39 // parameter, ListMeshes returns up to 100 results and a nextToken value if 40 // applicable. 41 Limit *int32 42 43 // The nextToken value returned from a previous paginated ListMeshes request where 44 // limit was used and the results exceeded the value of that parameter. Pagination 45 // continues from the end of the previous results that returned the nextToken 46 // value. This token should be treated as an opaque identifier that is used only to 47 // retrieve the next items in a list and not for other programmatic purposes. 48 NextToken *string 49} 50 51// 52type ListMeshesOutput struct { 53 54 // The list of existing service meshes. 55 // 56 // This member is required. 57 Meshes []types.MeshRef 58 59 // The nextToken value to include in a future ListMeshes request. When the results 60 // of a ListMeshes request exceed limit, you can use this value to retrieve the 61 // next page of results. This value is null when there are no more results to 62 // return. 63 NextToken *string 64 65 // Metadata pertaining to the operation's result. 66 ResultMetadata middleware.Metadata 67} 68 69func addOperationListMeshesMiddlewares(stack *middleware.Stack, options Options) (err error) { 70 err = stack.Serialize.Add(&awsRestjson1_serializeOpListMeshes{}, middleware.After) 71 if err != nil { 72 return err 73 } 74 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListMeshes{}, middleware.After) 75 if err != nil { 76 return err 77 } 78 if err = addSetLoggerMiddleware(stack, options); err != nil { 79 return err 80 } 81 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 82 return err 83 } 84 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 85 return err 86 } 87 if err = addResolveEndpointMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 91 return err 92 } 93 if err = addRetryMiddlewares(stack, options); err != nil { 94 return err 95 } 96 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 97 return err 98 } 99 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 100 return err 101 } 102 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 103 return err 104 } 105 if err = addClientUserAgent(stack); err != nil { 106 return err 107 } 108 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 109 return err 110 } 111 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 112 return err 113 } 114 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 115 return err 116 } 117 if err = addResponseErrorMiddleware(stack); err != nil { 118 return err 119 } 120 if err = addRequestResponseLogging(stack, options); err != nil { 121 return err 122 } 123 return nil 124} 125 126// ListMeshesAPIClient is a client that implements the ListMeshes operation. 127type ListMeshesAPIClient interface { 128 ListMeshes(context.Context, *ListMeshesInput, ...func(*Options)) (*ListMeshesOutput, error) 129} 130 131var _ ListMeshesAPIClient = (*Client)(nil) 132 133// ListMeshesPaginatorOptions is the paginator options for ListMeshes 134type ListMeshesPaginatorOptions struct { 135 // The maximum number of results returned by ListMeshes in paginated output. When 136 // you use this parameter, ListMeshes returns only limit results in a single page 137 // along with a nextToken response element. You can see the remaining results of 138 // the initial request by sending another ListMeshes request with the returned 139 // nextToken value. This value can be between 1 and 100. If you don't use this 140 // parameter, ListMeshes returns up to 100 results and a nextToken value if 141 // applicable. 142 Limit int32 143 144 // Set to true if pagination should stop if the service returns a pagination token 145 // that matches the most recent token provided to the service. 146 StopOnDuplicateToken bool 147} 148 149// ListMeshesPaginator is a paginator for ListMeshes 150type ListMeshesPaginator struct { 151 options ListMeshesPaginatorOptions 152 client ListMeshesAPIClient 153 params *ListMeshesInput 154 nextToken *string 155 firstPage bool 156} 157 158// NewListMeshesPaginator returns a new ListMeshesPaginator 159func NewListMeshesPaginator(client ListMeshesAPIClient, params *ListMeshesInput, optFns ...func(*ListMeshesPaginatorOptions)) *ListMeshesPaginator { 160 if params == nil { 161 params = &ListMeshesInput{} 162 } 163 164 options := ListMeshesPaginatorOptions{} 165 if params.Limit != nil { 166 options.Limit = *params.Limit 167 } 168 169 for _, fn := range optFns { 170 fn(&options) 171 } 172 173 return &ListMeshesPaginator{ 174 options: options, 175 client: client, 176 params: params, 177 firstPage: true, 178 } 179} 180 181// HasMorePages returns a boolean indicating whether more pages are available 182func (p *ListMeshesPaginator) HasMorePages() bool { 183 return p.firstPage || p.nextToken != nil 184} 185 186// NextPage retrieves the next ListMeshes page. 187func (p *ListMeshesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListMeshesOutput, error) { 188 if !p.HasMorePages() { 189 return nil, fmt.Errorf("no more pages available") 190 } 191 192 params := *p.params 193 params.NextToken = p.nextToken 194 195 var limit *int32 196 if p.options.Limit > 0 { 197 limit = &p.options.Limit 198 } 199 params.Limit = limit 200 201 result, err := p.client.ListMeshes(ctx, ¶ms, optFns...) 202 if err != nil { 203 return nil, err 204 } 205 p.firstPage = false 206 207 prevToken := p.nextToken 208 p.nextToken = result.NextToken 209 210 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 211 p.nextToken = nil 212 } 213 214 return result, nil 215} 216