1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package mobile
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/mobile/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists projects in AWS Mobile Hub.
16func (c *Client) ListProjects(ctx context.Context, params *ListProjectsInput, optFns ...func(*Options)) (*ListProjectsOutput, error) {
17	if params == nil {
18		params = &ListProjectsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListProjects", params, optFns, addOperationListProjectsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListProjectsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31// Request structure used to request projects list in AWS Mobile Hub.
32type ListProjectsInput struct {
33
34	// Maximum number of records to list in a single response.
35	MaxResults int32
36
37	// Pagination token. Set to null to start listing projects from start. If non-null
38	// pagination token is returned in a result, then pass its value in here in another
39	// request to list more projects.
40	NextToken *string
41}
42
43// Result structure used for requests to list projects in AWS Mobile Hub.
44type ListProjectsOutput struct {
45
46	// Pagination token. Set to null to start listing records from start. If non-null
47	// pagination token is returned in a result, then pass its value in here in another
48	// request to list more entries.
49	NextToken *string
50
51	// List of projects.
52	Projects []types.ProjectSummary
53
54	// Metadata pertaining to the operation's result.
55	ResultMetadata middleware.Metadata
56}
57
58func addOperationListProjectsMiddlewares(stack *middleware.Stack, options Options) (err error) {
59	err = stack.Serialize.Add(&awsRestjson1_serializeOpListProjects{}, middleware.After)
60	if err != nil {
61		return err
62	}
63	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListProjects{}, middleware.After)
64	if err != nil {
65		return err
66	}
67	if err = addSetLoggerMiddleware(stack, options); err != nil {
68		return err
69	}
70	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
71		return err
72	}
73	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
74		return err
75	}
76	if err = addResolveEndpointMiddleware(stack, options); err != nil {
77		return err
78	}
79	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
80		return err
81	}
82	if err = addRetryMiddlewares(stack, options); err != nil {
83		return err
84	}
85	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
86		return err
87	}
88	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
89		return err
90	}
91	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
92		return err
93	}
94	if err = addClientUserAgent(stack); err != nil {
95		return err
96	}
97	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
98		return err
99	}
100	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
101		return err
102	}
103	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListProjects(options.Region), middleware.Before); err != nil {
104		return err
105	}
106	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
107		return err
108	}
109	if err = addResponseErrorMiddleware(stack); err != nil {
110		return err
111	}
112	if err = addRequestResponseLogging(stack, options); err != nil {
113		return err
114	}
115	return nil
116}
117
118// ListProjectsAPIClient is a client that implements the ListProjects operation.
119type ListProjectsAPIClient interface {
120	ListProjects(context.Context, *ListProjectsInput, ...func(*Options)) (*ListProjectsOutput, error)
121}
122
123var _ ListProjectsAPIClient = (*Client)(nil)
124
125// ListProjectsPaginatorOptions is the paginator options for ListProjects
126type ListProjectsPaginatorOptions struct {
127	// Maximum number of records to list in a single response.
128	Limit int32
129
130	// Set to true if pagination should stop if the service returns a pagination token
131	// that matches the most recent token provided to the service.
132	StopOnDuplicateToken bool
133}
134
135// ListProjectsPaginator is a paginator for ListProjects
136type ListProjectsPaginator struct {
137	options   ListProjectsPaginatorOptions
138	client    ListProjectsAPIClient
139	params    *ListProjectsInput
140	nextToken *string
141	firstPage bool
142}
143
144// NewListProjectsPaginator returns a new ListProjectsPaginator
145func NewListProjectsPaginator(client ListProjectsAPIClient, params *ListProjectsInput, optFns ...func(*ListProjectsPaginatorOptions)) *ListProjectsPaginator {
146	options := ListProjectsPaginatorOptions{}
147	if params.MaxResults != 0 {
148		options.Limit = params.MaxResults
149	}
150
151	for _, fn := range optFns {
152		fn(&options)
153	}
154
155	if params == nil {
156		params = &ListProjectsInput{}
157	}
158
159	return &ListProjectsPaginator{
160		options:   options,
161		client:    client,
162		params:    params,
163		firstPage: true,
164	}
165}
166
167// HasMorePages returns a boolean indicating whether more pages are available
168func (p *ListProjectsPaginator) HasMorePages() bool {
169	return p.firstPage || p.nextToken != nil
170}
171
172// NextPage retrieves the next ListProjects page.
173func (p *ListProjectsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListProjectsOutput, error) {
174	if !p.HasMorePages() {
175		return nil, fmt.Errorf("no more pages available")
176	}
177
178	params := *p.params
179	params.NextToken = p.nextToken
180
181	params.MaxResults = p.options.Limit
182
183	result, err := p.client.ListProjects(ctx, &params, optFns...)
184	if err != nil {
185		return nil, err
186	}
187	p.firstPage = false
188
189	prevToken := p.nextToken
190	p.nextToken = result.NextToken
191
192	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
193		p.nextToken = nil
194	}
195
196	return result, nil
197}
198
199func newServiceMetadataMiddleware_opListProjects(region string) *awsmiddleware.RegisterServiceMetadata {
200	return &awsmiddleware.RegisterServiceMetadata{
201		Region:        region,
202		ServiceID:     ServiceID,
203		SigningName:   "awsmobilehubservice",
204		OperationName: "ListProjects",
205	}
206}
207