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