1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ecs
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/ecs/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the services that are running in a specified cluster.
16func (c *Client) ListServices(ctx context.Context, params *ListServicesInput, optFns ...func(*Options)) (*ListServicesOutput, error) {
17	if params == nil {
18		params = &ListServicesInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListServices", params, optFns, addOperationListServicesMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListServicesOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListServicesInput struct {
32
33	// The short name or full Amazon Resource Name (ARN) of the cluster that hosts the
34	// services to list. If you do not specify a cluster, the default cluster is
35	// assumed.
36	Cluster *string
37
38	// The launch type for the services to list.
39	LaunchType types.LaunchType
40
41	// The maximum number of service results returned by ListServices in paginated
42	// output. When this parameter is used, ListServices only returns maxResults
43	// results in a single page along with a nextToken response element. The remaining
44	// results of the initial request can be seen by sending another ListServices
45	// request with the returned nextToken value. This value can be between 1 and 100.
46	// If this parameter is not used, then ListServices returns up to 10 results and a
47	// nextToken value if applicable.
48	MaxResults *int32
49
50	// The nextToken value returned from a ListServices request indicating that more
51	// results are available to fulfill the request and further calls will be needed.
52	// If maxResults was provided, it is possible the number of results to be fewer
53	// than maxResults. This token should be treated as an opaque identifier that is
54	// only used to retrieve the next items in a list and not for other programmatic
55	// purposes.
56	NextToken *string
57
58	// The scheduling strategy for services to list.
59	SchedulingStrategy types.SchedulingStrategy
60}
61
62type ListServicesOutput struct {
63
64	// The nextToken value to include in a future ListServices request. When the
65	// results of a ListServices request exceed maxResults, this value can be used to
66	// retrieve the next page of results. This value is null when there are no more
67	// results to return.
68	NextToken *string
69
70	// The list of full ARN entries for each service associated with the specified
71	// cluster.
72	ServiceArns []string
73
74	// Metadata pertaining to the operation's result.
75	ResultMetadata middleware.Metadata
76}
77
78func addOperationListServicesMiddlewares(stack *middleware.Stack, options Options) (err error) {
79	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListServices{}, middleware.After)
80	if err != nil {
81		return err
82	}
83	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListServices{}, middleware.After)
84	if err != nil {
85		return err
86	}
87	if err = addSetLoggerMiddleware(stack, options); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
91		return err
92	}
93	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
94		return err
95	}
96	if err = addResolveEndpointMiddleware(stack, options); err != nil {
97		return err
98	}
99	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
100		return err
101	}
102	if err = addRetryMiddlewares(stack, options); err != nil {
103		return err
104	}
105	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
112		return err
113	}
114	if err = addClientUserAgent(stack); err != nil {
115		return err
116	}
117	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListServices(options.Region), middleware.Before); err != nil {
124		return err
125	}
126	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
127		return err
128	}
129	if err = addResponseErrorMiddleware(stack); err != nil {
130		return err
131	}
132	if err = addRequestResponseLogging(stack, options); err != nil {
133		return err
134	}
135	return nil
136}
137
138// ListServicesAPIClient is a client that implements the ListServices operation.
139type ListServicesAPIClient interface {
140	ListServices(context.Context, *ListServicesInput, ...func(*Options)) (*ListServicesOutput, error)
141}
142
143var _ ListServicesAPIClient = (*Client)(nil)
144
145// ListServicesPaginatorOptions is the paginator options for ListServices
146type ListServicesPaginatorOptions struct {
147	// The maximum number of service results returned by ListServices in paginated
148	// output. When this parameter is used, ListServices only returns maxResults
149	// results in a single page along with a nextToken response element. The remaining
150	// results of the initial request can be seen by sending another ListServices
151	// request with the returned nextToken value. This value can be between 1 and 100.
152	// If this parameter is not used, then ListServices returns up to 10 results and a
153	// nextToken value if applicable.
154	Limit int32
155
156	// Set to true if pagination should stop if the service returns a pagination token
157	// that matches the most recent token provided to the service.
158	StopOnDuplicateToken bool
159}
160
161// ListServicesPaginator is a paginator for ListServices
162type ListServicesPaginator struct {
163	options   ListServicesPaginatorOptions
164	client    ListServicesAPIClient
165	params    *ListServicesInput
166	nextToken *string
167	firstPage bool
168}
169
170// NewListServicesPaginator returns a new ListServicesPaginator
171func NewListServicesPaginator(client ListServicesAPIClient, params *ListServicesInput, optFns ...func(*ListServicesPaginatorOptions)) *ListServicesPaginator {
172	options := ListServicesPaginatorOptions{}
173	if params.MaxResults != nil {
174		options.Limit = *params.MaxResults
175	}
176
177	for _, fn := range optFns {
178		fn(&options)
179	}
180
181	if params == nil {
182		params = &ListServicesInput{}
183	}
184
185	return &ListServicesPaginator{
186		options:   options,
187		client:    client,
188		params:    params,
189		firstPage: true,
190	}
191}
192
193// HasMorePages returns a boolean indicating whether more pages are available
194func (p *ListServicesPaginator) HasMorePages() bool {
195	return p.firstPage || p.nextToken != nil
196}
197
198// NextPage retrieves the next ListServices page.
199func (p *ListServicesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListServicesOutput, error) {
200	if !p.HasMorePages() {
201		return nil, fmt.Errorf("no more pages available")
202	}
203
204	params := *p.params
205	params.NextToken = p.nextToken
206
207	var limit *int32
208	if p.options.Limit > 0 {
209		limit = &p.options.Limit
210	}
211	params.MaxResults = limit
212
213	result, err := p.client.ListServices(ctx, &params, optFns...)
214	if err != nil {
215		return nil, err
216	}
217	p.firstPage = false
218
219	prevToken := p.nextToken
220	p.nextToken = result.NextToken
221
222	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
223		p.nextToken = nil
224	}
225
226	return result, nil
227}
228
229func newServiceMetadataMiddleware_opListServices(region string) *awsmiddleware.RegisterServiceMetadata {
230	return &awsmiddleware.RegisterServiceMetadata{
231		Region:        region,
232		ServiceID:     ServiceID,
233		SigningName:   "ecs",
234		OperationName: "ListServices",
235	}
236}
237