kinesis.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package aws
  15. type KinesisStream struct {
  16. StreamArn string
  17. StreamCreationTimestamp int
  18. StreamModeDetails struct {
  19. StreamMode string
  20. }
  21. StreamName string
  22. StreamStatus string
  23. Shards []struct {
  24. ShardId string
  25. }
  26. }
  27. func (self *SRegion) ListStreams() ([]KinesisStream, error) {
  28. params := map[string]interface{}{
  29. "MaxResults": "10000",
  30. }
  31. ret := []KinesisStream{}
  32. for {
  33. part := struct {
  34. StreamSummaries []KinesisStream
  35. NextToken string
  36. }{}
  37. err := self.kinesisRequest("ListStreams", "/listStreams", params, &part)
  38. if err != nil {
  39. return nil, err
  40. }
  41. ret = append(ret, part.StreamSummaries...)
  42. if len(part.StreamSummaries) == 0 || len(part.NextToken) == 0 {
  43. break
  44. }
  45. params["NextToken"] = part.NextToken
  46. }
  47. return ret, nil
  48. }
  49. func (self *SRegion) DescribeStream(name string) (*KinesisStream, error) {
  50. params := map[string]interface{}{
  51. "StreamName": name,
  52. }
  53. ret := struct {
  54. StreamDescription KinesisStream
  55. }{}
  56. err := self.kinesisRequest("DescribeStream", "/describeStream", params, &ret)
  57. if err != nil {
  58. return nil, err
  59. }
  60. return &ret.StreamDescription, nil
  61. }