-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.go
46 lines (37 loc) · 1.07 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package dynastore
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
type DynaSession struct {
*dynamodb.DynamoDB
storeHooks *StoreHooks
}
func (ds *DynaSession) Table(tableName string) *DynaTable {
return &DynaTable{session: ds, tableName: tableName}
}
// New construct a DynamoDB backed store with default session / service
func New(cfgs ...*aws.Config) *DynaSession {
sess := session.Must(session.NewSession(cfgs...))
dynamoSvc := dynamodb.New(sess)
return &DynaSession{
dynamoSvc, defaultHooks,
}
}
// New construct a DynamoDB backed store with default session / service
func NewWithOptions(awscfg *aws.Config, options ...SessionOption) *DynaSession {
sessionOptions := NewSessionOptions(options...)
sess := session.Must(session.NewSession(awscfg))
dynamoSvc := dynamodb.New(sess)
return &DynaSession{
dynamoSvc,
sessionOptions.storeHooks,
}
}
func NewWithClient(dynamoSvc *dynamodb.DynamoDB, storeHooks *StoreHooks) *DynaSession {
return &DynaSession{
dynamoSvc,
storeHooks,
}
}