dynamodbstore

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 11 Imported by: 0

README

dynamodbstore GoDoc

A session store backend for gorilla/sessions which uses AWS DynamoDB. It uses the official AWS Golang SDK.

Installation

go get -u github.com/wolfeidau/dynamodbstore

Usage

    // you may want to configure this centrally in your application
    sess := session.Must(session.NewSession())

    ddb := dynamodb.New(sess)

    // secret-key should be generated
    secretKey := "secret-key-should-be-in-config"
    
    store, err := dynamodbstore.NewDynamodbStore(ddb, []byte(secretKey))
	if err != nil {
		log.Fatal(err)
	}

    // Get a session.
    session, err = store.Get(req, "session-key")
    if err != nil {
        log.Error(err)
    }

    // Add a value.
    session.Values["foo"] = "bar"

    // Save.
    if err = sessions.Save(req, rsp); err != nil {
        log.Fatalf("Error saving session: %v", err)
    }

    // Delete session.
    session.Options.MaxAge = -1
    if err = sessions.Save(req, rsp); err != nil {
        log.Fatalf("Error saving session: %v", err)
    }

License

This code is released under MIT License, and is copyright Mark Wolfe.

Documentation

Index

Constants

View Source
const DefaultSessionExpire = 86400 * 30

DefaultSessionExpire expiry time in seconds for cookies/dynamodb keys to expire

View Source
const DefaultTableName = "SessionTable"

DefaultTableName default dynamodb session table name

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamodbStore

type DynamodbStore struct {
	DB            *dynamodb.DynamoDB
	TableName     string
	Codecs        []securecookie.Codec
	Options       *sessions.Options // default configuration
	DefaultMaxAge int               // default Redis TTL for a MaxAge == 0 session
	// contains filtered or unexported fields
}

DynamodbStore stores sessions in a dynamodb backend.

func NewDynamodbStore

func NewDynamodbStore(ddb *dynamodb.DynamoDB, keyPairs ...[]byte) (*DynamodbStore, error)

NewDynamodbStore create a new store using the supplied DynamoDB session

func NewDynamodbStoreWithOptions added in v1.1.0

func NewDynamodbStoreWithOptions(ddb *dynamodb.DynamoDB, options ...Option) *DynamodbStore

NewDynamodbStoreWithOptions new dynamodb session store using options

func (*DynamodbStore) CreateTable

func (s *DynamodbStore) CreateTable(readCapacityUnits, writeCapacityUnits int64) error

CreateTable setup a new table for session records using the configured table name

func (*DynamodbStore) DropTable

func (s *DynamodbStore) DropTable() error

DropTable delete table for session records using the configured table name

func (*DynamodbStore) Get

func (s *DynamodbStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

See gorilla/sessions FilesystemStore.Get().

func (*DynamodbStore) New

func (s *DynamodbStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns a session for the given name without adding it to the registry.

See gorilla/sessions FilesystemStore.New().

func (*DynamodbStore) Save

Save adds a single session to the response.

type Option added in v1.1.0

type Option func(opts *StoreOptions)

Option used to configure the store

func DefaultMaxAge added in v1.1.0

func DefaultMaxAge(age int) Option

DefaultMaxAge update the default max age provided to github.com/gorilla/sessions

func KeyPairs added in v1.1.0

func KeyPairs(keyPairs ...[]byte) Option

KeyPairs update the key pairs provided to github.com/gorilla/sessions

func SessionOptions added in v1.1.0

func SessionOptions(sessionOpts *sessions.Options) Option

SessionOptions update the session options provided to github.com/gorilla/sessions

func TableName added in v1.1.0

func TableName(name string) Option

TableName update the table name

type StoreOptions added in v1.1.0

type StoreOptions struct {
	// contains filtered or unexported fields
}

StoreOptions used to configure the dynamodb session store

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL