AWS DynamoDB store for Gorilla Toolkit using AWS library. Includes support for DynamoDB's TTL feature.
Uses the official AWS library, github.com/aws/aws-sdk-go/aws
go get github.com/savaki/dynastore/...
dynastore uses the common AWS environment variables:
AWS_DEFAULT_REGION
orAWS_REGION
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
dynastore will also use AWS roles if they are available. In that case, only
AWS_DEFAULT_REGION
or AWS_REGION
need be set.
Alternately, AWS settings can be specified using Options:
dynastore.AWSConfig(*aws.Config)
dynastore.DynamoDB(*dynamodb.DynamoDB)
dynastore provides a utility to create/delete the dynamodb table.
dynastore -table your-table-name -read 5 -write 5
Use the -delete flag to indicate the tables should be deleted instead.
dynastore -table your-table-name -delete
// Create Store
store, err := dynastore.New(dynastore.Path("/"), dynastore.HTTPOnly())
if err != nil {
log.Fatalln(err)
}
// Get Session
session, err := store.Get(req, "session-key")
if err != nil {
log.Fatalln(err)
}
// Add a Value
session.Values["hello"] = "world"
// Save Session
err := session.Save(req, w)
if err != nil {
log.Fatalln(err)
}
// Delete Session
session.Options.MaxAge = -1
err := session.Save(req, w)
if err != nil {
log.Fatalln(err)
}