1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iotwireless
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/iotwireless/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the destinations registered to your AWS account.
16func (c *Client) ListDestinations(ctx context.Context, params *ListDestinationsInput, optFns ...func(*Options)) (*ListDestinationsOutput, error) {
17	if params == nil {
18		params = &ListDestinationsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListDestinations", params, optFns, addOperationListDestinationsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListDestinationsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListDestinationsInput struct {
32
33	// The maximum number of results to return in this operation.
34	MaxResults int32
35
36	// To retrieve the next set of results, the nextToken value from a previous
37	// response; otherwise null to receive the first set of results.
38	NextToken *string
39}
40
41type ListDestinationsOutput struct {
42
43	// The list of destinations.
44	DestinationList []types.Destinations
45
46	// The token to use to get the next set of results, or null if there are no
47	// additional results.
48	NextToken *string
49
50	// Metadata pertaining to the operation's result.
51	ResultMetadata middleware.Metadata
52}
53
54func addOperationListDestinationsMiddlewares(stack *middleware.Stack, options Options) (err error) {
55	err = stack.Serialize.Add(&awsRestjson1_serializeOpListDestinations{}, middleware.After)
56	if err != nil {
57		return err
58	}
59	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListDestinations{}, middleware.After)
60	if err != nil {
61		return err
62	}
63	if err = addSetLoggerMiddleware(stack, options); err != nil {
64		return err
65	}
66	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
67		return err
68	}
69	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
70		return err
71	}
72	if err = addResolveEndpointMiddleware(stack, options); err != nil {
73		return err
74	}
75	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
76		return err
77	}
78	if err = addRetryMiddlewares(stack, options); err != nil {
79		return err
80	}
81	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
82		return err
83	}
84	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
85		return err
86	}
87	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
88		return err
89	}
90	if err = addClientUserAgent(stack); err != nil {
91		return err
92	}
93	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
97		return err
98	}
99	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListDestinations(options.Region), middleware.Before); 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// ListDestinationsAPIClient is a client that implements the ListDestinations
115// operation.
116type ListDestinationsAPIClient interface {
117	ListDestinations(context.Context, *ListDestinationsInput, ...func(*Options)) (*ListDestinationsOutput, error)
118}
119
120var _ ListDestinationsAPIClient = (*Client)(nil)
121
122// ListDestinationsPaginatorOptions is the paginator options for ListDestinations
123type ListDestinationsPaginatorOptions struct {
124	// The maximum number of results to return in this operation.
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// ListDestinationsPaginator is a paginator for ListDestinations
133type ListDestinationsPaginator struct {
134	options   ListDestinationsPaginatorOptions
135	client    ListDestinationsAPIClient
136	params    *ListDestinationsInput
137	nextToken *string
138	firstPage bool
139}
140
141// NewListDestinationsPaginator returns a new ListDestinationsPaginator
142func NewListDestinationsPaginator(client ListDestinationsAPIClient, params *ListDestinationsInput, optFns ...func(*ListDestinationsPaginatorOptions)) *ListDestinationsPaginator {
143	options := ListDestinationsPaginatorOptions{}
144	if params.MaxResults != 0 {
145		options.Limit = params.MaxResults
146	}
147
148	for _, fn := range optFns {
149		fn(&options)
150	}
151
152	if params == nil {
153		params = &ListDestinationsInput{}
154	}
155
156	return &ListDestinationsPaginator{
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 *ListDestinationsPaginator) HasMorePages() bool {
166	return p.firstPage || p.nextToken != nil
167}
168
169// NextPage retrieves the next ListDestinations page.
170func (p *ListDestinationsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListDestinationsOutput, 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	params.MaxResults = p.options.Limit
179
180	result, err := p.client.ListDestinations(ctx, &params, optFns...)
181	if err != nil {
182		return nil, err
183	}
184	p.firstPage = false
185
186	prevToken := p.nextToken
187	p.nextToken = result.NextToken
188
189	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
190		p.nextToken = nil
191	}
192
193	return result, nil
194}
195
196func newServiceMetadataMiddleware_opListDestinations(region string) *awsmiddleware.RegisterServiceMetadata {
197	return &awsmiddleware.RegisterServiceMetadata{
198		Region:        region,
199		ServiceID:     ServiceID,
200		SigningName:   "iotwireless",
201		OperationName: "ListDestinations",
202	}
203}
204