1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package location
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/location/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists map resources in your AWS account.
16func (c *Client) ListMaps(ctx context.Context, params *ListMapsInput, optFns ...func(*Options)) (*ListMapsOutput, error) {
17	if params == nil {
18		params = &ListMapsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListMaps", params, optFns, addOperationListMapsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListMapsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListMapsInput struct {
32
33	// An optional limit for the number of resources returned in a single call. Default
34	// value: 100
35	MaxResults *int32
36
37	// The pagination token specifying which page of results to return in the response.
38	// If no token is provided, the default page is the first page. Default value: null
39	NextToken *string
40}
41
42type ListMapsOutput struct {
43
44	// Contains a list of maps in your AWS account
45	//
46	// This member is required.
47	Entries []types.ListMapsResponseEntry
48
49	// A pagination token indicating there are additional pages available. You can use
50	// the token in a following request to fetch the next set of results.
51	NextToken *string
52
53	// Metadata pertaining to the operation's result.
54	ResultMetadata middleware.Metadata
55}
56
57func addOperationListMapsMiddlewares(stack *middleware.Stack, options Options) (err error) {
58	err = stack.Serialize.Add(&awsRestjson1_serializeOpListMaps{}, middleware.After)
59	if err != nil {
60		return err
61	}
62	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListMaps{}, middleware.After)
63	if err != nil {
64		return err
65	}
66	if err = addSetLoggerMiddleware(stack, options); err != nil {
67		return err
68	}
69	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
70		return err
71	}
72	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
73		return err
74	}
75	if err = addResolveEndpointMiddleware(stack, options); err != nil {
76		return err
77	}
78	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
79		return err
80	}
81	if err = addRetryMiddlewares(stack, options); err != nil {
82		return err
83	}
84	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
85		return err
86	}
87	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
91		return err
92	}
93	if err = addClientUserAgent(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
97		return err
98	}
99	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
100		return err
101	}
102	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
103		return err
104	}
105	if err = addResponseErrorMiddleware(stack); err != nil {
106		return err
107	}
108	if err = addRequestResponseLogging(stack, options); err != nil {
109		return err
110	}
111	return nil
112}
113
114// ListMapsAPIClient is a client that implements the ListMaps operation.
115type ListMapsAPIClient interface {
116	ListMaps(context.Context, *ListMapsInput, ...func(*Options)) (*ListMapsOutput, error)
117}
118
119var _ ListMapsAPIClient = (*Client)(nil)
120
121// ListMapsPaginatorOptions is the paginator options for ListMaps
122type ListMapsPaginatorOptions struct {
123	// An optional limit for the number of resources returned in a single call. Default
124	// value: 100
125	Limit int32
126
127	// Set to true if pagination should stop if the service returns a pagination token
128	// that matches the most recent token provided to the service.
129	StopOnDuplicateToken bool
130}
131
132// ListMapsPaginator is a paginator for ListMaps
133type ListMapsPaginator struct {
134	options   ListMapsPaginatorOptions
135	client    ListMapsAPIClient
136	params    *ListMapsInput
137	nextToken *string
138	firstPage bool
139}
140
141// NewListMapsPaginator returns a new ListMapsPaginator
142func NewListMapsPaginator(client ListMapsAPIClient, params *ListMapsInput, optFns ...func(*ListMapsPaginatorOptions)) *ListMapsPaginator {
143	if params == nil {
144		params = &ListMapsInput{}
145	}
146
147	options := ListMapsPaginatorOptions{}
148	if params.MaxResults != nil {
149		options.Limit = *params.MaxResults
150	}
151
152	for _, fn := range optFns {
153		fn(&options)
154	}
155
156	return &ListMapsPaginator{
157		options:   options,
158		client:    client,
159		params:    params,
160		firstPage: true,
161	}
162}
163
164// HasMorePages returns a boolean indicating whether more pages are available
165func (p *ListMapsPaginator) HasMorePages() bool {
166	return p.firstPage || p.nextToken != nil
167}
168
169// NextPage retrieves the next ListMaps page.
170func (p *ListMapsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListMapsOutput, error) {
171	if !p.HasMorePages() {
172		return nil, fmt.Errorf("no more pages available")
173	}
174
175	params := *p.params
176	params.NextToken = p.nextToken
177
178	var limit *int32
179	if p.options.Limit > 0 {
180		limit = &p.options.Limit
181	}
182	params.MaxResults = limit
183
184	result, err := p.client.ListMaps(ctx, &params, optFns...)
185	if err != nil {
186		return nil, err
187	}
188	p.firstPage = false
189
190	prevToken := p.nextToken
191	p.nextToken = result.NextToken
192
193	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
194		p.nextToken = nil
195	}
196
197	return result, nil
198}
199