Documentation ¶
Overview ¶
Package dynamostore is a DynamoDB-based storage engine for the SCS session package.
The dynamostore package relis on the aws-sdk-go client. (https://godoc.org/github.com/aws/aws-sdk-go/service/dynamodb)
Usage:
package main import ( "net/http" "github.com/alexedwards/scs/session" "github.com/alexedwards/scs/engine/dynamostore" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/endpoints" awsSession "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" ) func main() { // Create a DynamoDB client. conf := &aws.Config{Region: aws.String(endpoints.UsEast1RegionID)} dynamo := dynamodb.New(awsSession.New(), conf) // Create a new DynamoStore instance using the DynamoDB client. engine := dynamostore.New(dynamo) sessionManager := session.Manage(engine) http.ListenAndServe(":4000", sessionManager(http.DefaultServeMux)) }
Index ¶
- type DynamoStore
- func (d *DynamoStore) DataName() string
- func (d *DynamoStore) Delete(token string) error
- func (d *DynamoStore) ExpiryName() string
- func (d *DynamoStore) Find(token string) (b []byte, found bool, err error)
- func (d *DynamoStore) Ping() error
- func (d *DynamoStore) Save(token string, b []byte, expiry time.Time) error
- func (d *DynamoStore) TTLName() string
- func (d *DynamoStore) TableName() string
- func (d *DynamoStore) TokenName() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynamoStore ¶
DynamoStore represents the currently configured session storage engine. It is essentially a wrapper around a DynamoDB client. And table is a table name session stored. token, data, expiry are key names.
func New ¶
func New(dynamo *dynamodb.DynamoDB) *DynamoStore
New returns a new DynamoStore instance. The client parameter shoud be a pointer to a aws-sdk-go DynamoDB client. See https://godoc.org/github.com/aws/aws-sdk-go/service/dynamodb#DynamoDB.
func NewWithOption ¶
func NewWithOption(dynamo *dynamodb.DynamoDB, table string, token string, data string, expiry string, ttl string) *DynamoStore
NewWithOption returns a new DynamoStore instance. The client parameter shoud be a pointer to a aws-sdk-go DynamoDB client. See https://godoc.org/github.com/aws/aws-sdk-go/service/dynamodb#DynamoDB. The parameter table is DynamoDB tabel name, and token/data/expiry are key names.
func (*DynamoStore) DataName ¶
func (d *DynamoStore) DataName() string
DataName returns session data key name.
func (*DynamoStore) Delete ¶
func (d *DynamoStore) Delete(token string) error
Delete removes a session token and corresponding data from the ResisStore instance.
func (*DynamoStore) ExpiryName ¶
func (d *DynamoStore) ExpiryName() string
ExpiryName returns session expiry key name.
func (*DynamoStore) Find ¶
func (d *DynamoStore) Find(token string) (b []byte, found bool, err error)
Find returns the data for a given session token from the DynamoStore instance. If the session token is not found or is expired, the returned exists flag will be set to false.
func (*DynamoStore) Ping ¶
func (d *DynamoStore) Ping() error
Ping checks to exisit session table in DynamoDB.
func (*DynamoStore) Save ¶
Save adds a session token and data to the RedisStore instance with the given expiry time. If the session token already exists then the data and expiry time are updated.
func (*DynamoStore) TTLName ¶
func (d *DynamoStore) TTLName() string
TTLName returns session expiry key name.
func (*DynamoStore) TableName ¶
func (d *DynamoStore) TableName() string
TableName returns session table name.
func (*DynamoStore) TokenName ¶
func (d *DynamoStore) TokenName() string
TokenName returns session token key name.