Skip to content

Commit 801ec47

Browse files
committed
Fix DAX support (closes #4)
1 parent aa9e182 commit 801ec47

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

main.go

+33-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/aws/aws-sdk-go/service/dax"
1111
"github.com/aws/aws-sdk-go/service/dynamodb"
1212
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
13-
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
1413
"github.com/davecgh/go-spew/spew"
1514
"github.com/mattn/go-colorable"
1615
"github.com/mattn/go-isatty"
@@ -25,11 +24,36 @@ var maxCount int
2524
var daxCluster string
2625

2726
type Dynamo struct {
28-
api dynamodbiface.DynamoDBAPI
27+
api *Api
2928
w io.Writer
3029
emitted int
3130
}
3231

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+
3357
func main() {
3458
/*
3559
len(os.Args)
@@ -57,16 +81,18 @@ func main() {
5781
d.Run(args)
5882
}
5983

60-
func apiClient(daxCluster string) dynamodbiface.DynamoDBAPI {
84+
func apiClient(daxCluster string) *Api {
6185
sess, err := session.NewSessionWithOptions(session.Options{
6286
SharedConfigState: session.SharedConfigEnable,
6387
})
6488
if err != nil {
6589
panic(err)
6690
}
6791

92+
api := &Api{dynamo: dynamodb.New(sess)}
93+
6894
if len(daxCluster) == 0 {
69-
return dynamodb.New(sess)
95+
return api
7096
}
7197

7298
if !strings.Contains(daxCluster, ".") {
@@ -95,7 +121,7 @@ func apiClient(daxCluster string) dynamodbiface.DynamoDBAPI {
95121
cfg.Credentials = sess.Config.Credentials
96122
cfg.Region = *sess.Config.Region
97123

98-
api, err := daxc.New(cfg)
124+
api.dax, err = daxc.New(cfg)
99125
if err != nil {
100126
panic(err)
101127
}
@@ -163,7 +189,7 @@ func (d *Dynamo) write(jsonItems []interface{}) bool {
163189
return true
164190
}
165191

166-
func queryForArgs(api dynamodbiface.DynamoDBAPI, args []string) (*dynamodb.QueryInput, error) {
192+
func queryForArgs(api *Api, args []string) (*dynamodb.QueryInput, error) {
167193
table := args[0]
168194
tableDescription, _ := tableDescription(api, table)
169195

@@ -225,7 +251,7 @@ func queryForArgs(api dynamodbiface.DynamoDBAPI, args []string) (*dynamodb.Query
225251
return input, nil
226252
}
227253

228-
func tableDescription(api dynamodbiface.DynamoDBAPI, table string) (*dynamodb.TableDescription, error) {
254+
func tableDescription(api *Api, table string) (*dynamodb.TableDescription, error) {
229255
describeResp, _ := api.DescribeTable(&dynamodb.DescribeTableInput{TableName: &table})
230256
tableDescription := describeResp.Table
231257
return tableDescription, nil

0 commit comments

Comments
 (0)