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 for all the services that are associated with one or
16// more specified namespaces.
17func (c *Client) ListServices(ctx context.Context, params *ListServicesInput, optFns ...func(*Options)) (*ListServicesOutput, error) {
18	if params == nil {
19		params = &ListServicesInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListServices", params, optFns, addOperationListServicesMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListServicesOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListServicesInput struct {
33
34	// A complex type that contains specifications for the namespaces that you want to
35	// list services for. If you specify more than one filter, an operation must match
36	// all filters to be returned by ListServices.
37	Filters []types.ServiceFilter
38
39	// The maximum number of services that you want AWS Cloud Map to return in the
40	// response to a ListServices request. If you don't specify a value for MaxResults,
41	// AWS Cloud Map returns up to 100 services.
42	MaxResults *int32
43
44	// For the first ListServices request, omit this value. If the response contains
45	// NextToken, submit another ListServices request to get the next group of results.
46	// Specify the value of NextToken from the previous response in the next request.
47	// AWS Cloud Map gets MaxResults services and then filters them based on the
48	// specified criteria. It's possible that no services in the first MaxResults
49	// services matched the specified criteria but that subsequent groups of MaxResults
50	// services do contain services that match the criteria.
51	NextToken *string
52}
53
54type ListServicesOutput struct {
55
56	// If the response contains NextToken, submit another ListServices request to get
57	// the next group of results. Specify the value of NextToken from the previous
58	// response in the next request. AWS Cloud Map gets MaxResults services and then
59	// filters them based on the specified criteria. It's possible that no services in
60	// the first MaxResults services matched the specified criteria but that subsequent
61	// groups of MaxResults services do contain services that match the criteria.
62	NextToken *string
63
64	// An array that contains one ServiceSummary object for each service that matches
65	// the specified filter criteria.
66	Services []types.ServiceSummary
67
68	// Metadata pertaining to the operation's result.
69	ResultMetadata middleware.Metadata
70}
71
72func addOperationListServicesMiddlewares(stack *middleware.Stack, options Options) (err error) {
73	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListServices{}, middleware.After)
74	if err != nil {
75		return err
76	}
77	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListServices{}, 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 = addOpListServicesValidationMiddleware(stack); err != nil {
118		return err
119	}
120	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListServices(options.Region), middleware.Before); err != nil {
121		return err
122	}
123	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addResponseErrorMiddleware(stack); err != nil {
127		return err
128	}
129	if err = addRequestResponseLogging(stack, options); err != nil {
130		return err
131	}
132	return nil
133}
134
135// ListServicesAPIClient is a client that implements the ListServices operation.
136type ListServicesAPIClient interface {
137	ListServices(context.Context, *ListServicesInput, ...func(*Options)) (*ListServicesOutput, error)
138}
139
140var _ ListServicesAPIClient = (*Client)(nil)
141
142// ListServicesPaginatorOptions is the paginator options for ListServices
143type ListServicesPaginatorOptions struct {
144	// The maximum number of services that you want AWS Cloud Map to return in the
145	// response to a ListServices request. If you don't specify a value for MaxResults,
146	// AWS Cloud Map returns up to 100 services.
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// ListServicesPaginator is a paginator for ListServices
155type ListServicesPaginator struct {
156	options   ListServicesPaginatorOptions
157	client    ListServicesAPIClient
158	params    *ListServicesInput
159	nextToken *string
160	firstPage bool
161}
162
163// NewListServicesPaginator returns a new ListServicesPaginator
164func NewListServicesPaginator(client ListServicesAPIClient, params *ListServicesInput, optFns ...func(*ListServicesPaginatorOptions)) *ListServicesPaginator {
165	options := ListServicesPaginatorOptions{}
166	if params.MaxResults != nil {
167		options.Limit = *params.MaxResults
168	}
169
170	for _, fn := range optFns {
171		fn(&options)
172	}
173
174	if params == nil {
175		params = &ListServicesInput{}
176	}
177
178	return &ListServicesPaginator{
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 *ListServicesPaginator) HasMorePages() bool {
188	return p.firstPage || p.nextToken != nil
189}
190
191// NextPage retrieves the next ListServices page.
192func (p *ListServicesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListServicesOutput, 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.ListServices(ctx, &params, 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_opListServices(region string) *awsmiddleware.RegisterServiceMetadata {
223	return &awsmiddleware.RegisterServiceMetadata{
224		Region:        region,
225		ServiceID:     ServiceID,
226		SigningName:   "servicediscovery",
227		OperationName: "ListServices",
228	}
229}
230