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