Only initialize ddb client if none is provided (#106)

This commit is contained in:
Patrik Karlström 2020-01-17 19:02:37 +01:00 committed by Harlow Ward
parent f85f25c15e
commit 217999854b
2 changed files with 11 additions and 2 deletions

2
go.mod
View file

@ -19,3 +19,5 @@ require (
google.golang.org/appengine v1.6.1 // indirect
gopkg.in/redis.v5 v5.2.9 // indirect
)
go 1.13

View file

@ -39,12 +39,10 @@ func WithRetryer(r Retryer) Option {
// New returns a checkpoint that uses DynamoDB for underlying storage
func New(appName, tableName string, opts ...Option) (*Checkpoint, error) {
client := dynamodb.New(session.New(aws.NewConfig()))
ck := &Checkpoint{
tableName: tableName,
appName: appName,
client: client,
maxInterval: time.Duration(1 * time.Minute),
done: make(chan struct{}),
mu: &sync.Mutex{},
@ -56,6 +54,15 @@ func New(appName, tableName string, opts ...Option) (*Checkpoint, error) {
opt(ck)
}
// default client
if ck.client == nil {
newSession, err := session.NewSession(aws.NewConfig())
if err != nil {
return nil, err
}
ck.client = dynamodb.New(newSession)
}
go ck.loop()
return ck, nil