forked from blinsay/ktk
/
list.go
55 lines (43 loc) · 1.07 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
// TODO(benl): Describe the streams instead of just listing names.
import (
"log"
"github.com/blinsay/ktk/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/kinesis"
)
var listCommand = &Command{
Name: "list",
Usage: "list",
Short: "list Kinesis streams",
Description: `
List the Kinesis streams associated with your account.
`,
Run: runList,
}
// List the names of all of the Kinesis streams.
func runList(args []string) {
// Ignore args
streams, err := listStreams(kinesis.New(nil))
fatalOnErr(err)
for _, stream := range streams {
log.Println(stream)
}
}
func listStreams(k *kinesis.Kinesis) ([]string, error) {
streams := make([]string, 0)
request := &kinesis.ListStreamsInput{}
hasMoreStreams := true
for hasMoreStreams {
resp, err := k.ListStreams(request)
if err != nil {
return nil, err
}
for _, streamName := range resp.StreamNames {
streams = append(streams, *streamName)
}
if !*resp.HasMoreStreams {
break
}
request.ExclusiveStartStreamName = resp.StreamNames[len(resp.StreamNames)-1]
}
return streams, nil
}