Only initialize ddb client if none is provided
This commit is contained in:
parent
f85f25c15e
commit
e5ac9128d7
2 changed files with 11 additions and 2 deletions
2
go.mod
2
go.mod
|
|
@ -19,3 +19,5 @@ require (
|
||||||
google.golang.org/appengine v1.6.1 // indirect
|
google.golang.org/appengine v1.6.1 // indirect
|
||||||
gopkg.in/redis.v5 v5.2.9 // indirect
|
gopkg.in/redis.v5 v5.2.9 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,10 @@ func WithRetryer(r Retryer) Option {
|
||||||
|
|
||||||
// New returns a checkpoint that uses DynamoDB for underlying storage
|
// New returns a checkpoint that uses DynamoDB for underlying storage
|
||||||
func New(appName, tableName string, opts ...Option) (*Checkpoint, error) {
|
func New(appName, tableName string, opts ...Option) (*Checkpoint, error) {
|
||||||
client := dynamodb.New(session.New(aws.NewConfig()))
|
|
||||||
|
|
||||||
ck := &Checkpoint{
|
ck := &Checkpoint{
|
||||||
tableName: tableName,
|
tableName: tableName,
|
||||||
appName: appName,
|
appName: appName,
|
||||||
client: client,
|
|
||||||
maxInterval: time.Duration(1 * time.Minute),
|
maxInterval: time.Duration(1 * time.Minute),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
mu: &sync.Mutex{},
|
mu: &sync.Mutex{},
|
||||||
|
|
@ -56,6 +54,15 @@ func New(appName, tableName string, opts ...Option) (*Checkpoint, error) {
|
||||||
opt(ck)
|
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()
|
go ck.loop()
|
||||||
|
|
||||||
return ck, nil
|
return ck, nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue