1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package elasticache 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/elasticache/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13 "time" 14) 15 16// Returns events related to clusters, cache security groups, and cache parameter 17// groups. You can obtain events specific to a particular cluster, cache security 18// group, or cache parameter group by providing the name as a parameter. By 19// default, only the events occurring within the last hour are returned; however, 20// you can retrieve up to 14 days' worth of events if necessary. 21func (c *Client) DescribeEvents(ctx context.Context, params *DescribeEventsInput, optFns ...func(*Options)) (*DescribeEventsOutput, error) { 22 if params == nil { 23 params = &DescribeEventsInput{} 24 } 25 26 result, metadata, err := c.invokeOperation(ctx, "DescribeEvents", params, optFns, addOperationDescribeEventsMiddlewares) 27 if err != nil { 28 return nil, err 29 } 30 31 out := result.(*DescribeEventsOutput) 32 out.ResultMetadata = metadata 33 return out, nil 34} 35 36// Represents the input of a DescribeEvents operation. 37type DescribeEventsInput struct { 38 39 // The number of minutes worth of events to retrieve. 40 Duration *int32 41 42 // The end of the time interval for which to retrieve events, specified in ISO 8601 43 // format. Example: 2017-03-30T07:03:49.555Z 44 EndTime *time.Time 45 46 // An optional marker returned from a prior request. Use this marker for pagination 47 // of results from this operation. If this parameter is specified, the response 48 // includes only records beyond the marker, up to the value specified by 49 // MaxRecords. 50 Marker *string 51 52 // The maximum number of records to include in the response. If more records exist 53 // than the specified MaxRecords value, a marker is included in the response so 54 // that the remaining results can be retrieved. Default: 100 Constraints: minimum 55 // 20; maximum 100. 56 MaxRecords *int32 57 58 // The identifier of the event source for which events are returned. If not 59 // specified, all sources are included in the response. 60 SourceIdentifier *string 61 62 // The event source to retrieve events for. If no value is specified, all events 63 // are returned. 64 SourceType types.SourceType 65 66 // The beginning of the time interval to retrieve events for, specified in ISO 8601 67 // format. Example: 2017-03-30T07:03:49.555Z 68 StartTime *time.Time 69} 70 71// Represents the output of a DescribeEvents operation. 72type DescribeEventsOutput struct { 73 74 // A list of events. Each element in the list contains detailed information about 75 // one event. 76 Events []types.Event 77 78 // Provides an identifier to allow retrieval of paginated results. 79 Marker *string 80 81 // Metadata pertaining to the operation's result. 82 ResultMetadata middleware.Metadata 83} 84 85func addOperationDescribeEventsMiddlewares(stack *middleware.Stack, options Options) (err error) { 86 err = stack.Serialize.Add(&awsAwsquery_serializeOpDescribeEvents{}, middleware.After) 87 if err != nil { 88 return err 89 } 90 err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDescribeEvents{}, middleware.After) 91 if err != nil { 92 return err 93 } 94 if err = addSetLoggerMiddleware(stack, options); err != nil { 95 return err 96 } 97 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 98 return err 99 } 100 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 101 return err 102 } 103 if err = addResolveEndpointMiddleware(stack, options); err != nil { 104 return err 105 } 106 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 107 return err 108 } 109 if err = addRetryMiddlewares(stack, options); err != nil { 110 return err 111 } 112 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 113 return err 114 } 115 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 116 return err 117 } 118 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 119 return err 120 } 121 if err = addClientUserAgent(stack); err != nil { 122 return err 123 } 124 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 125 return err 126 } 127 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 128 return err 129 } 130 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeEvents(options.Region), middleware.Before); err != nil { 131 return err 132 } 133 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 134 return err 135 } 136 if err = addResponseErrorMiddleware(stack); err != nil { 137 return err 138 } 139 if err = addRequestResponseLogging(stack, options); err != nil { 140 return err 141 } 142 return nil 143} 144 145// DescribeEventsAPIClient is a client that implements the DescribeEvents 146// operation. 147type DescribeEventsAPIClient interface { 148 DescribeEvents(context.Context, *DescribeEventsInput, ...func(*Options)) (*DescribeEventsOutput, error) 149} 150 151var _ DescribeEventsAPIClient = (*Client)(nil) 152 153// DescribeEventsPaginatorOptions is the paginator options for DescribeEvents 154type DescribeEventsPaginatorOptions struct { 155 // The maximum number of records to include in the response. If more records exist 156 // than the specified MaxRecords value, a marker is included in the response so 157 // that the remaining results can be retrieved. Default: 100 Constraints: minimum 158 // 20; maximum 100. 159 Limit int32 160 161 // Set to true if pagination should stop if the service returns a pagination token 162 // that matches the most recent token provided to the service. 163 StopOnDuplicateToken bool 164} 165 166// DescribeEventsPaginator is a paginator for DescribeEvents 167type DescribeEventsPaginator struct { 168 options DescribeEventsPaginatorOptions 169 client DescribeEventsAPIClient 170 params *DescribeEventsInput 171 nextToken *string 172 firstPage bool 173} 174 175// NewDescribeEventsPaginator returns a new DescribeEventsPaginator 176func NewDescribeEventsPaginator(client DescribeEventsAPIClient, params *DescribeEventsInput, optFns ...func(*DescribeEventsPaginatorOptions)) *DescribeEventsPaginator { 177 options := DescribeEventsPaginatorOptions{} 178 if params.MaxRecords != nil { 179 options.Limit = *params.MaxRecords 180 } 181 182 for _, fn := range optFns { 183 fn(&options) 184 } 185 186 if params == nil { 187 params = &DescribeEventsInput{} 188 } 189 190 return &DescribeEventsPaginator{ 191 options: options, 192 client: client, 193 params: params, 194 firstPage: true, 195 } 196} 197 198// HasMorePages returns a boolean indicating whether more pages are available 199func (p *DescribeEventsPaginator) HasMorePages() bool { 200 return p.firstPage || p.nextToken != nil 201} 202 203// NextPage retrieves the next DescribeEvents page. 204func (p *DescribeEventsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeEventsOutput, error) { 205 if !p.HasMorePages() { 206 return nil, fmt.Errorf("no more pages available") 207 } 208 209 params := *p.params 210 params.Marker = p.nextToken 211 212 var limit *int32 213 if p.options.Limit > 0 { 214 limit = &p.options.Limit 215 } 216 params.MaxRecords = limit 217 218 result, err := p.client.DescribeEvents(ctx, ¶ms, optFns...) 219 if err != nil { 220 return nil, err 221 } 222 p.firstPage = false 223 224 prevToken := p.nextToken 225 p.nextToken = result.Marker 226 227 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 228 p.nextToken = nil 229 } 230 231 return result, nil 232} 233 234func newServiceMetadataMiddleware_opDescribeEvents(region string) *awsmiddleware.RegisterServiceMetadata { 235 return &awsmiddleware.RegisterServiceMetadata{ 236 Region: region, 237 ServiceID: ServiceID, 238 SigningName: "elasticache", 239 OperationName: "DescribeEvents", 240 } 241} 242