api_op_DescribeLogStreams.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 the log streams for the specified log group. You can list all the log
  13. // streams or filter the results by prefix. You can also control how the results
  14. // are ordered. This operation has a limit of five transactions per second, after
  15. // which transactions are throttled.
  16. func (c *Client) DescribeLogStreams(ctx context.Context, params *DescribeLogStreamsInput, optFns ...func(*Options)) (*DescribeLogStreamsOutput, error) {
  17. if params == nil {
  18. params = &DescribeLogStreamsInput{}
  19. }
  20. result, metadata, err := c.invokeOperation(ctx, "DescribeLogStreams", params, optFns, c.addOperationDescribeLogStreamsMiddlewares)
  21. if err != nil {
  22. return nil, err
  23. }
  24. out := result.(*DescribeLogStreamsOutput)
  25. out.ResultMetadata = metadata
  26. return out, nil
  27. }
  28. type DescribeLogStreamsInput struct {
  29. // The name of the log group.
  30. //
  31. // This member is required.
  32. LogGroupName *string
  33. // If the value is true, results are returned in descending order. If the value is
  34. // to false, results are returned in ascending order. The default value is false.
  35. Descending *bool
  36. // The maximum number of items returned. If you don't specify a value, the default
  37. // is up to 50 items.
  38. Limit *int32
  39. // The prefix to match. If orderBy is LastEventTime, you cannot specify this
  40. // parameter.
  41. LogStreamNamePrefix *string
  42. // The token for the next set of items to return. (You received this token from a
  43. // previous call.)
  44. NextToken *string
  45. // If the value is LogStreamName, the results are ordered by log stream name. If
  46. // the value is LastEventTime, the results are ordered by the event time. The
  47. // default value is LogStreamName. If you order the results by event time, you
  48. // cannot specify the logStreamNamePrefix parameter. lastEventTimestamp represents
  49. // the time of the most recent log event in the log stream in CloudWatch Logs. This
  50. // number is expressed as the number of milliseconds after Jan 1, 1970 00:00:00
  51. // UTC. lastEventTimestamp updates on an eventual consistency basis. It typically
  52. // updates in less than an hour from ingestion, but in rare situations might take
  53. // longer.
  54. OrderBy types.OrderBy
  55. noSmithyDocumentSerde
  56. }
  57. type DescribeLogStreamsOutput struct {
  58. // The log streams.
  59. LogStreams []types.LogStream
  60. // The token for the next set of items to return. The token expires after 24 hours.
  61. NextToken *string
  62. // Metadata pertaining to the operation's result.
  63. ResultMetadata middleware.Metadata
  64. noSmithyDocumentSerde
  65. }
  66. func (c *Client) addOperationDescribeLogStreamsMiddlewares(stack *middleware.Stack, options Options) (err error) {
  67. err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeLogStreams{}, middleware.After)
  68. if err != nil {
  69. return err
  70. }
  71. err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeLogStreams{}, middleware.After)
  72. if err != nil {
  73. return err
  74. }
  75. if err = addSetLoggerMiddleware(stack, options); err != nil {
  76. return err
  77. }
  78. if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
  79. return err
  80. }
  81. if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
  82. return err
  83. }
  84. if err = addResolveEndpointMiddleware(stack, options); err != nil {
  85. return err
  86. }
  87. if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
  88. return err
  89. }
  90. if err = addRetryMiddlewares(stack, options); err != nil {
  91. return err
  92. }
  93. if err = addHTTPSignerV4Middleware(stack, options); err != nil {
  94. return err
  95. }
  96. if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
  97. return err
  98. }
  99. if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
  100. return err
  101. }
  102. if err = addClientUserAgent(stack); err != nil {
  103. return err
  104. }
  105. if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
  106. return err
  107. }
  108. if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
  109. return err
  110. }
  111. if err = addOpDescribeLogStreamsValidationMiddleware(stack); err != nil {
  112. return err
  113. }
  114. if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeLogStreams(options.Region), middleware.Before); err != nil {
  115. return err
  116. }
  117. if err = addRequestIDRetrieverMiddleware(stack); err != nil {
  118. return err
  119. }
  120. if err = addResponseErrorMiddleware(stack); err != nil {
  121. return err
  122. }
  123. if err = addRequestResponseLogging(stack, options); err != nil {
  124. return err
  125. }
  126. return nil
  127. }
  128. // DescribeLogStreamsAPIClient is a client that implements the DescribeLogStreams
  129. // operation.
  130. type DescribeLogStreamsAPIClient interface {
  131. DescribeLogStreams(context.Context, *DescribeLogStreamsInput, ...func(*Options)) (*DescribeLogStreamsOutput, error)
  132. }
  133. var _ DescribeLogStreamsAPIClient = (*Client)(nil)
  134. // DescribeLogStreamsPaginatorOptions is the paginator options for
  135. // DescribeLogStreams
  136. type DescribeLogStreamsPaginatorOptions struct {
  137. // The maximum number of items returned. If you don't specify a value, the default
  138. // is up to 50 items.
  139. Limit int32
  140. // Set to true if pagination should stop if the service returns a pagination token
  141. // that matches the most recent token provided to the service.
  142. StopOnDuplicateToken bool
  143. }
  144. // DescribeLogStreamsPaginator is a paginator for DescribeLogStreams
  145. type DescribeLogStreamsPaginator struct {
  146. options DescribeLogStreamsPaginatorOptions
  147. client DescribeLogStreamsAPIClient
  148. params *DescribeLogStreamsInput
  149. nextToken *string
  150. firstPage bool
  151. }
  152. // NewDescribeLogStreamsPaginator returns a new DescribeLogStreamsPaginator
  153. func NewDescribeLogStreamsPaginator(client DescribeLogStreamsAPIClient, params *DescribeLogStreamsInput, optFns ...func(*DescribeLogStreamsPaginatorOptions)) *DescribeLogStreamsPaginator {
  154. if params == nil {
  155. params = &DescribeLogStreamsInput{}
  156. }
  157. options := DescribeLogStreamsPaginatorOptions{}
  158. if params.Limit != nil {
  159. options.Limit = *params.Limit
  160. }
  161. for _, fn := range optFns {
  162. fn(&options)
  163. }
  164. return &DescribeLogStreamsPaginator{
  165. options: options,
  166. client: client,
  167. params: params,
  168. firstPage: true,
  169. nextToken: params.NextToken,
  170. }
  171. }
  172. // HasMorePages returns a boolean indicating whether more pages are available
  173. func (p *DescribeLogStreamsPaginator) HasMorePages() bool {
  174. return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0)
  175. }
  176. // NextPage retrieves the next DescribeLogStreams page.
  177. func (p *DescribeLogStreamsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeLogStreamsOutput, error) {
  178. if !p.HasMorePages() {
  179. return nil, fmt.Errorf("no more pages available")
  180. }
  181. params := *p.params
  182. params.NextToken = p.nextToken
  183. var limit *int32
  184. if p.options.Limit > 0 {
  185. limit = &p.options.Limit
  186. }
  187. params.Limit = limit
  188. result, err := p.client.DescribeLogStreams(ctx, &params, optFns...)
  189. if err != nil {
  190. return nil, err
  191. }
  192. p.firstPage = false
  193. prevToken := p.nextToken
  194. p.nextToken = result.NextToken
  195. if p.options.StopOnDuplicateToken &&
  196. prevToken != nil &&
  197. p.nextToken != nil &&
  198. *prevToken == *p.nextToken {
  199. p.nextToken = nil
  200. }
  201. return result, nil
  202. }
  203. func newServiceMetadataMiddleware_opDescribeLogStreams(region string) *awsmiddleware.RegisterServiceMetadata {
  204. return &awsmiddleware.RegisterServiceMetadata{
  205. Region: region,
  206. ServiceID: ServiceID,
  207. SigningName: "logs",
  208. OperationName: "DescribeLogStreams",
  209. }
  210. }