Skip to content

Commit

Permalink
Fix DAX support (closes #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidansteele committed Mar 20, 2020
1 parent aa9e182 commit 801ec47
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/aws/aws-sdk-go/service/dax"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
"github.com/davecgh/go-spew/spew"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
Expand All @@ -25,11 +24,36 @@ var maxCount int
var daxCluster string

type Dynamo struct {
api dynamodbiface.DynamoDBAPI
api *Api
w io.Writer
emitted int
}

type Api struct {
dynamo *dynamodb.DynamoDB
dax *daxc.Dax
}

func (a *Api) DescribeTable(input *dynamodb.DescribeTableInput) (*dynamodb.DescribeTableOutput, error) {
return a.dynamo.DescribeTable(input)
}

func (a *Api) QueryPages(input *dynamodb.QueryInput, cb func(*dynamodb.QueryOutput, bool) bool) error {
if a.dax != nil {
return a.dax.QueryPages(input, cb)
}

return a.dynamo.QueryPages(input, cb)
}

func (a *Api) ScanPages(input *dynamodb.ScanInput, cb func(*dynamodb.ScanOutput, bool) bool) error {
if a.dax != nil {
return a.dax.ScanPages(input, cb)
}

return a.dynamo.ScanPages(input, cb)
}

func main() {
/*
len(os.Args)
Expand Down Expand Up @@ -57,16 +81,18 @@ func main() {
d.Run(args)
}

func apiClient(daxCluster string) dynamodbiface.DynamoDBAPI {
func apiClient(daxCluster string) *Api {
sess, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
panic(err)
}

api := &Api{dynamo: dynamodb.New(sess)}

if len(daxCluster) == 0 {
return dynamodb.New(sess)
return api
}

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

api, err := daxc.New(cfg)
api.dax, err = daxc.New(cfg)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -163,7 +189,7 @@ func (d *Dynamo) write(jsonItems []interface{}) bool {
return true
}

func queryForArgs(api dynamodbiface.DynamoDBAPI, args []string) (*dynamodb.QueryInput, error) {
func queryForArgs(api *Api, args []string) (*dynamodb.QueryInput, error) {
table := args[0]
tableDescription, _ := tableDescription(api, table)

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

func tableDescription(api dynamodbiface.DynamoDBAPI, table string) (*dynamodb.TableDescription, error) {
func tableDescription(api *Api, table string) (*dynamodb.TableDescription, error) {
describeResp, _ := api.DescribeTable(&dynamodb.DescribeTableInput{TableName: &table})
tableDescription := describeResp.Table
return tableDescription, nil
Expand Down

0 comments on commit 801ec47

Please sign in to comment.