Skip to content

Commit c91990d

Browse files
author
Xu Ao
committed
Not panic in GetDynamoSession
1 parent 85961e3 commit c91990d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

db/dbsession.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
var DynamoDB *dynamodb.DynamoDB
1212

1313
// GetDynamoSession returns a new dynamodb session
14-
func GetDynamoSession(accessKeyID, secretAccessKey, region string) *dynamodb.DynamoDB {
14+
func GetDynamoSession(accessKeyID, secretAccessKey, region string) (*dynamodb.DynamoDB, error) {
1515
sessionConfig := session.Options{}
1616
if accessKeyID != "" || secretAccessKey != "" {
1717
token := ""
1818
creds := credentials.NewStaticCredentials(accessKeyID, secretAccessKey, token)
1919
_, err := creds.Get()
2020
if err != nil {
21-
panic(err)
21+
return nil, err
2222
}
2323
sessionConfig.Config.Credentials = creds
2424
}
@@ -31,10 +31,10 @@ func GetDynamoSession(accessKeyID, secretAccessKey, region string) *dynamodb.Dyn
3131

3232
session, err := session.NewSessionWithOptions(sessionConfig)
3333
if err != nil {
34-
panic(err)
34+
return nil, err
3535
}
3636
DynamoDB = dynamodb.New(session)
37-
return DynamoDB
37+
return DynamoDB, nil
3838
}
3939

4040
// ListTable returns all table names from dynamoDB

0 commit comments

Comments
 (0)