1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package servicediscovery
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/servicediscovery/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists summary information about the namespaces that were created by the current
16// account.
17func (c *Client) ListNamespaces(ctx context.Context, params *ListNamespacesInput, optFns ...func(*Options)) (*ListNamespacesOutput, error) {
18	if params == nil {
19		params = &ListNamespacesInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListNamespaces", params, optFns, c.addOperationListNamespacesMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListNamespacesOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListNamespacesInput struct {
33
34	// A complex type that contains specifications for the namespaces that you want to
35	// list. If you specify more than one filter, a namespace must match all filters to
36	// be returned by ListNamespaces.
37	Filters []types.NamespaceFilter
38
39	// The maximum number of namespaces that you want Cloud Map to return in the
40	// response to a ListNamespaces request. If you don't specify a value for
41	// MaxResults, Cloud Map returns up to 100 namespaces.
42	MaxResults *int32
43
44	// For the first ListNamespaces request, omit this value. If the response contains
45	// NextToken, submit another ListNamespaces request to get the next group of
46	// results. Specify the value of NextToken from the previous response in the next
47	// request. Cloud Map gets MaxResults namespaces and then filters them based on the
48	// specified criteria. It's possible that no namespaces in the first MaxResults
49	// namespaces matched the specified criteria but that subsequent groups of
50	// MaxResults namespaces do contain namespaces that match the criteria.
51	NextToken *string
52
53	noSmithyDocumentSerde
54}
55
56type ListNamespacesOutput struct {
57
58	// An array that contains one NamespaceSummary object for each namespace that
59	// matches the specified filter criteria.
60	Namespaces []types.NamespaceSummary
61
62	// If the response contains NextToken, submit another ListNamespaces request to get
63	// the next group of results. Specify the value of NextToken from the previous
64	// response in the next request. Cloud Map gets MaxResults namespaces and then
65	// filters them based on the specified criteria. It's possible that no namespaces
66	// in the first MaxResults namespaces matched the specified criteria but that
67	// subsequent groups of MaxResults namespaces do contain namespaces that match the
68	// criteria.
69	NextToken *string
70
71	// Metadata pertaining to the operation's result.
72	ResultMetadata middleware.Metadata
73
74	noSmithyDocumentSerde
75}
76
77func (c *Client) addOperationListNamespacesMiddlewares(stack *middleware.Stack, options Options) (err error) {
78	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListNamespaces{}, middleware.After)
79	if err != nil {
80		return err
81	}
82	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListNamespaces{}, middleware.After)
83	if err != nil {
84		return err
85	}
86	if err = addSetLoggerMiddleware(stack, options); err != nil {
87		return err
88	}
89	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
90		return err
91	}
92	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
93		return err
94	}
95	if err = addResolveEndpointMiddleware(stack, options); err != nil {
96		return err
97	}
98	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
99		return err
100	}
101	if err = addRetryMiddlewares(stack, options); err != nil {
102		return err
103	}
104	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
105		return err
106	}
107	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
108		return err
109	}
110	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
111		return err
112	}
113	if err = addClientUserAgent(stack); err != nil {
114		return err
115	}
116	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
117		return err
118	}
119	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addOpListNamespacesValidationMiddleware(stack); err != nil {
123		return err
124	}
125	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListNamespaces(options.Region), middleware.Before); err != nil {
126		return err
127	}
128	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addResponseErrorMiddleware(stack); err != nil {
132		return err
133	}
134	if err = addRequestResponseLogging(stack, options); err != nil {
135		return err
136	}
137	return nil
138}
139
140// ListNamespacesAPIClient is a client that implements the ListNamespaces
141// operation.
142type ListNamespacesAPIClient interface {
143	ListNamespaces(context.Context, *ListNamespacesInput, ...func(*Options)) (*ListNamespacesOutput, error)
144}
145
146var _ ListNamespacesAPIClient = (*Client)(nil)
147
148// ListNamespacesPaginatorOptions is the paginator options for ListNamespaces
149type ListNamespacesPaginatorOptions struct {
150	// The maximum number of namespaces that you want Cloud Map to return in the
151	// response to a ListNamespaces request. If you don't specify a value for
152	// MaxResults, Cloud Map returns up to 100 namespaces.
153	Limit int32
154
155	// Set to true if pagination should stop if the service returns a pagination token
156	// that matches the most recent token provided to the service.
157	StopOnDuplicateToken bool
158}
159
160// ListNamespacesPaginator is a paginator for ListNamespaces
161type ListNamespacesPaginator struct {
162	options   ListNamespacesPaginatorOptions
163	client    ListNamespacesAPIClient
164	params    *ListNamespacesInput
165	nextToken *string
166	firstPage bool
167}
168
169// NewListNamespacesPaginator returns a new ListNamespacesPaginator
170func NewListNamespacesPaginator(client ListNamespacesAPIClient, params *ListNamespacesInput, optFns ...func(*ListNamespacesPaginatorOptions)) *ListNamespacesPaginator {
171	if params == nil {
172		params = &ListNamespacesInput{}
173	}
174
175	options := ListNamespacesPaginatorOptions{}
176	if params.MaxResults != nil {
177		options.Limit = *params.MaxResults
178	}
179
180	for _, fn := range optFns {
181		fn(&options)
182	}
183
184	return &ListNamespacesPaginator{
185		options:   options,
186		client:    client,
187		params:    params,
188		firstPage: true,
189	}
190}
191
192// HasMorePages returns a boolean indicating whether more pages are available
193func (p *ListNamespacesPaginator) HasMorePages() bool {
194	return p.firstPage || p.nextToken != nil
195}
196
197// NextPage retrieves the next ListNamespaces page.
198func (p *ListNamespacesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListNamespacesOutput, error) {
199	if !p.HasMorePages() {
200		return nil, fmt.Errorf("no more pages available")
201	}
202
203	params := *p.params
204	params.NextToken = p.nextToken
205
206	var limit *int32
207	if p.options.Limit > 0 {
208		limit = &p.options.Limit
209	}
210	params.MaxResults = limit
211
212	result, err := p.client.ListNamespaces(ctx, &params, optFns...)
213	if err != nil {
214		return nil, err
215	}
216	p.firstPage = false
217
218	prevToken := p.nextToken
219	p.nextToken = result.NextToken
220
221	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
222		p.nextToken = nil
223	}
224
225	return result, nil
226}
227
228func newServiceMetadataMiddleware_opListNamespaces(region string) *awsmiddleware.RegisterServiceMetadata {
229	return &awsmiddleware.RegisterServiceMetadata{
230		Region:        region,
231		ServiceID:     ServiceID,
232		SigningName:   "servicediscovery",
233		OperationName: "ListNamespaces",
234	}
235}
236