@@ -10,7 +10,6 @@ import (
10
10
"github.com/aws/aws-sdk-go/service/dax"
11
11
"github.com/aws/aws-sdk-go/service/dynamodb"
12
12
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
13
- "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
14
13
"github.com/davecgh/go-spew/spew"
15
14
"github.com/mattn/go-colorable"
16
15
"github.com/mattn/go-isatty"
@@ -25,11 +24,36 @@ var maxCount int
25
24
var daxCluster string
26
25
27
26
type Dynamo struct {
28
- api dynamodbiface. DynamoDBAPI
27
+ api * Api
29
28
w io.Writer
30
29
emitted int
31
30
}
32
31
32
+ type Api struct {
33
+ dynamo * dynamodb.DynamoDB
34
+ dax * daxc.Dax
35
+ }
36
+
37
+ func (a * Api ) DescribeTable (input * dynamodb.DescribeTableInput ) (* dynamodb.DescribeTableOutput , error ) {
38
+ return a .dynamo .DescribeTable (input )
39
+ }
40
+
41
+ func (a * Api ) QueryPages (input * dynamodb.QueryInput , cb func (* dynamodb.QueryOutput , bool ) bool ) error {
42
+ if a .dax != nil {
43
+ return a .dax .QueryPages (input , cb )
44
+ }
45
+
46
+ return a .dynamo .QueryPages (input , cb )
47
+ }
48
+
49
+ func (a * Api ) ScanPages (input * dynamodb.ScanInput , cb func (* dynamodb.ScanOutput , bool ) bool ) error {
50
+ if a .dax != nil {
51
+ return a .dax .ScanPages (input , cb )
52
+ }
53
+
54
+ return a .dynamo .ScanPages (input , cb )
55
+ }
56
+
33
57
func main () {
34
58
/*
35
59
len(os.Args)
@@ -57,16 +81,18 @@ func main() {
57
81
d .Run (args )
58
82
}
59
83
60
- func apiClient (daxCluster string ) dynamodbiface. DynamoDBAPI {
84
+ func apiClient (daxCluster string ) * Api {
61
85
sess , err := session .NewSessionWithOptions (session.Options {
62
86
SharedConfigState : session .SharedConfigEnable ,
63
87
})
64
88
if err != nil {
65
89
panic (err )
66
90
}
67
91
92
+ api := & Api {dynamo : dynamodb .New (sess )}
93
+
68
94
if len (daxCluster ) == 0 {
69
- return dynamodb . New ( sess )
95
+ return api
70
96
}
71
97
72
98
if ! strings .Contains (daxCluster , "." ) {
@@ -95,7 +121,7 @@ func apiClient(daxCluster string) dynamodbiface.DynamoDBAPI {
95
121
cfg .Credentials = sess .Config .Credentials
96
122
cfg .Region = * sess .Config .Region
97
123
98
- api , err : = daxc .New (cfg )
124
+ api . dax , err = daxc .New (cfg )
99
125
if err != nil {
100
126
panic (err )
101
127
}
@@ -163,7 +189,7 @@ func (d *Dynamo) write(jsonItems []interface{}) bool {
163
189
return true
164
190
}
165
191
166
- func queryForArgs (api dynamodbiface. DynamoDBAPI , args []string ) (* dynamodb.QueryInput , error ) {
192
+ func queryForArgs (api * Api , args []string ) (* dynamodb.QueryInput , error ) {
167
193
table := args [0 ]
168
194
tableDescription , _ := tableDescription (api , table )
169
195
@@ -225,7 +251,7 @@ func queryForArgs(api dynamodbiface.DynamoDBAPI, args []string) (*dynamodb.Query
225
251
return input , nil
226
252
}
227
253
228
- func tableDescription (api dynamodbiface. DynamoDBAPI , table string ) (* dynamodb.TableDescription , error ) {
254
+ func tableDescription (api * Api , table string ) (* dynamodb.TableDescription , error ) {
229
255
describeResp , _ := api .DescribeTable (& dynamodb.DescribeTableInput {TableName : & table })
230
256
tableDescription := describeResp .Table
231
257
return tableDescription , nil
0 commit comments