api_op_GetLogEvents.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // Code generated by smithy-go-codegen DO NOT EDIT.
  2. package cloudwatchlogs
  3. import (
  4. "context"
  5. "fmt"
  6. awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
  7. "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
  8. "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
  9. "github.com/aws/smithy-go/middleware"
  10. smithyhttp "github.com/aws/smithy-go/transport/http"
  11. )
  12. // Lists log events from the specified log stream. You can list all of the log
  13. // events or filter using a time range. By default, this operation returns as many
  14. // log events as can fit in a response size of 1MB (up to 10,000 log events). You
  15. // can get additional log events by specifying one of the tokens in a subsequent
  16. // call. This operation can return empty results while there are more log events
  17. // available through the token.
  18. func (c *Client) GetLogEvents(ctx context.Context, params *GetLogEventsInput, optFns ...func(*Options)) (*GetLogEventsOutput, error) {
  19. if params == nil {
  20. params = &GetLogEventsInput{}
  21. }
  22. result, metadata, err := c.invokeOperation(ctx, "GetLogEvents", params, optFns, c.addOperationGetLogEventsMiddlewares)
  23. if err != nil {
  24. return nil, err
  25. }
  26. out := result.(*GetLogEventsOutput)
  27. out.ResultMetadata = metadata
  28. return out, nil
  29. }
  30. type GetLogEventsInput struct {
  31. // The name of the log group.
  32. //
  33. // This member is required.
  34. LogGroupName *string
  35. // The name of the log stream.
  36. //
  37. // This member is required.
  38. LogStreamName *string
  39. // The end of the time range, expressed as the number of milliseconds after Jan 1,
  40. // 1970 00:00:00 UTC. Events with a timestamp equal to or later than this time are
  41. // not included.
  42. EndTime *int64
  43. // The maximum number of log events returned. If you don't specify a value, the
  44. // maximum is as many log events as can fit in a response size of 1 MB, up to
  45. // 10,000 log events.
  46. Limit *int32
  47. // The token for the next set of items to return. (You received this token from a
  48. // previous call.)
  49. NextToken *string
  50. // If the value is true, the earliest log events are returned first. If the value
  51. // is false, the latest log events are returned first. The default value is false.
  52. // If you are using a previous nextForwardToken value as the nextToken in this
  53. // operation, you must specify true for startFromHead.
  54. StartFromHead *bool
  55. // The start of the time range, expressed as the number of milliseconds after Jan
  56. // 1, 1970 00:00:00 UTC. Events with a timestamp equal to this time or later than
  57. // this time are included. Events with a timestamp earlier than this time are not
  58. // included.
  59. StartTime *int64
  60. noSmithyDocumentSerde
  61. }
  62. type GetLogEventsOutput struct {
  63. // The events.
  64. Events []types.OutputLogEvent
  65. // The token for the next set of items in the backward direction. The token expires
  66. // after 24 hours. This token is never null. If you have reached the end of the
  67. // stream, it returns the same token you passed in.
  68. NextBackwardToken *string
  69. // The token for the next set of items in the forward direction. The token expires
  70. // after 24 hours. If you have reached the end of the stream, it returns the same
  71. // token you passed in.
  72. NextForwardToken *string
  73. // Metadata pertaining to the operation's result.
  74. ResultMetadata middleware.Metadata
  75. noSmithyDocumentSerde
  76. }
  77. func (c *Client) addOperationGetLogEventsMiddlewares(stack *middleware.Stack, options Options) (err error) {
  78. err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetLogEvents{}, middleware.After)
  79. if err != nil {
  80. return err
  81. }
  82. err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetLogEvents{}, middleware.After)
  83. if err != nil {
  84. return err
  85. }
  86. if err = addSetLoggerMiddleware(stack, options); err != nil {
  87. return err
  88. }
  89. if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
  90. return err
  91. }
  92. if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
  93. return err
  94. }
  95. if err = addResolveEndpointMiddleware(stack, options); err != nil {
  96. return err
  97. }
  98. if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
  99. return err
  100. }
  101. if err = addRetryMiddlewares(stack, options); err != nil {
  102. return err
  103. }
  104. if err = addHTTPSignerV4Middleware(stack, options); err != nil {
  105. return err
  106. }
  107. if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
  108. return err
  109. }
  110. if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
  111. return err
  112. }
  113. if err = addClientUserAgent(stack); err != nil {
  114. return err
  115. }
  116. if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
  117. return err
  118. }
  119. if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
  120. return err
  121. }
  122. if err = addOpGetLogEventsValidationMiddleware(stack); err != nil {
  123. return err
  124. }
  125. if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetLogEvents(options.Region), middleware.Before); err != nil {
  126. return err
  127. }
  128. if err = addRequestIDRetrieverMiddleware(stack); err != nil {
  129. return err
  130. }
  131. if err = addResponseErrorMiddleware(stack); err != nil {
  132. return err
  133. }
  134. if err = addRequestResponseLogging(stack, options); err != nil {
  135. return err
  136. }
  137. return nil
  138. }
  139. // GetLogEventsAPIClient is a client that implements the GetLogEvents operation.
  140. type GetLogEventsAPIClient interface {
  141. GetLogEvents(context.Context, *GetLogEventsInput, ...func(*Options)) (*GetLogEventsOutput, error)
  142. }
  143. var _ GetLogEventsAPIClient = (*Client)(nil)
  144. // GetLogEventsPaginatorOptions is the paginator options for GetLogEvents
  145. type GetLogEventsPaginatorOptions struct {
  146. // The maximum number of log events returned. If you don't specify a value, the
  147. // maximum is as many log events as can fit in a response size of 1 MB, up to
  148. // 10,000 log events.
  149. Limit int32
  150. // Set to true if pagination should stop if the service returns a pagination token
  151. // that matches the most recent token provided to the service.
  152. StopOnDuplicateToken bool
  153. }
  154. // GetLogEventsPaginator is a paginator for GetLogEvents
  155. type GetLogEventsPaginator struct {
  156. options GetLogEventsPaginatorOptions
  157. client GetLogEventsAPIClient
  158. params *GetLogEventsInput
  159. nextToken *string
  160. firstPage bool
  161. }
  162. // NewGetLogEventsPaginator returns a new GetLogEventsPaginator
  163. func NewGetLogEventsPaginator(client GetLogEventsAPIClient, params *GetLogEventsInput, optFns ...func(*GetLogEventsPaginatorOptions)) *GetLogEventsPaginator {
  164. if params == nil {
  165. params = &GetLogEventsInput{}
  166. }
  167. options := GetLogEventsPaginatorOptions{}
  168. if params.Limit != nil {
  169. options.Limit = *params.Limit
  170. }
  171. for _, fn := range optFns {
  172. fn(&options)
  173. }
  174. return &GetLogEventsPaginator{
  175. options: options,
  176. client: client,
  177. params: params,
  178. firstPage: true,
  179. nextToken: params.NextToken,
  180. }
  181. }
  182. // HasMorePages returns a boolean indicating whether more pages are available
  183. func (p *GetLogEventsPaginator) HasMorePages() bool {
  184. return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0)
  185. }
  186. // NextPage retrieves the next GetLogEvents page.
  187. func (p *GetLogEventsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetLogEventsOutput, error) {
  188. if !p.HasMorePages() {
  189. return nil, fmt.Errorf("no more pages available")
  190. }
  191. params := *p.params
  192. params.NextToken = p.nextToken
  193. var limit *int32
  194. if p.options.Limit > 0 {
  195. limit = &p.options.Limit
  196. }
  197. params.Limit = limit
  198. result, err := p.client.GetLogEvents(ctx, &params, optFns...)
  199. if err != nil {
  200. return nil, err
  201. }
  202. p.firstPage = false
  203. prevToken := p.nextToken
  204. p.nextToken = result.NextForwardToken
  205. if p.options.StopOnDuplicateToken &&
  206. prevToken != nil &&
  207. p.nextToken != nil &&
  208. *prevToken == *p.nextToken {
  209. p.nextToken = nil
  210. }
  211. return result, nil
  212. }
  213. func newServiceMetadataMiddleware_opGetLogEvents(region string) *awsmiddleware.RegisterServiceMetadata {
  214. return &awsmiddleware.RegisterServiceMetadata{
  215. Region: region,
  216. ServiceID: ServiceID,
  217. SigningName: "logs",
  218. OperationName: "GetLogEvents",
  219. }
  220. }