1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package lookoutmetrics 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/lookoutmetrics/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists the alerts attached to a detector. 16func (c *Client) ListAlerts(ctx context.Context, params *ListAlertsInput, optFns ...func(*Options)) (*ListAlertsOutput, error) { 17 if params == nil { 18 params = &ListAlertsInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListAlerts", params, optFns, addOperationListAlertsMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListAlertsOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListAlertsInput struct { 32 33 // The ARN of the alert's detector. 34 AnomalyDetectorArn *string 35 36 // The maximum number of results that will be displayed by the request. 37 MaxResults int32 38 39 // If the result of the previous request is truncated, the response includes a 40 // NextToken. To retrieve the next set of results, use the token in the next 41 // request. Tokens expire after 24 hours. 42 NextToken *string 43} 44 45type ListAlertsOutput struct { 46 47 // Contains information about an alert. 48 AlertSummaryList []types.AlertSummary 49 50 // If the response is truncated, the service returns this token. To retrieve the 51 // next set of results, use this token in the next request. 52 NextToken *string 53 54 // Metadata pertaining to the operation's result. 55 ResultMetadata middleware.Metadata 56} 57 58func addOperationListAlertsMiddlewares(stack *middleware.Stack, options Options) (err error) { 59 err = stack.Serialize.Add(&awsRestjson1_serializeOpListAlerts{}, middleware.After) 60 if err != nil { 61 return err 62 } 63 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListAlerts{}, 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_opListAlerts(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// ListAlertsAPIClient is a client that implements the ListAlerts operation. 119type ListAlertsAPIClient interface { 120 ListAlerts(context.Context, *ListAlertsInput, ...func(*Options)) (*ListAlertsOutput, error) 121} 122 123var _ ListAlertsAPIClient = (*Client)(nil) 124 125// ListAlertsPaginatorOptions is the paginator options for ListAlerts 126type ListAlertsPaginatorOptions struct { 127 // The maximum number of results that will be displayed by the request. 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// ListAlertsPaginator is a paginator for ListAlerts 136type ListAlertsPaginator struct { 137 options ListAlertsPaginatorOptions 138 client ListAlertsAPIClient 139 params *ListAlertsInput 140 nextToken *string 141 firstPage bool 142} 143 144// NewListAlertsPaginator returns a new ListAlertsPaginator 145func NewListAlertsPaginator(client ListAlertsAPIClient, params *ListAlertsInput, optFns ...func(*ListAlertsPaginatorOptions)) *ListAlertsPaginator { 146 if params == nil { 147 params = &ListAlertsInput{} 148 } 149 150 options := ListAlertsPaginatorOptions{} 151 if params.MaxResults != 0 { 152 options.Limit = params.MaxResults 153 } 154 155 for _, fn := range optFns { 156 fn(&options) 157 } 158 159 return &ListAlertsPaginator{ 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 *ListAlertsPaginator) HasMorePages() bool { 169 return p.firstPage || p.nextToken != nil 170} 171 172// NextPage retrieves the next ListAlerts page. 173func (p *ListAlertsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAlertsOutput, 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.ListAlerts(ctx, ¶ms, 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_opListAlerts(region string) *awsmiddleware.RegisterServiceMetadata { 200 return &awsmiddleware.RegisterServiceMetadata{ 201 Region: region, 202 ServiceID: ServiceID, 203 SigningName: "lookoutmetrics", 204 OperationName: "ListAlerts", 205 } 206} 207