dynamo

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dynamo stores login sessions in DynamoDB.

It exists so a deployment with no relational database can still log a user in. Importing it registers the backend and the session table; the client itself belongs to database/dynamo, which this package reads from the request context:

import _ "github.com/shibukawa/popcornweb/database/dynamo"
import _ "github.com/shibukawa/popcornweb/sessionstore/dynamo"

Nothing here sweeps expired records. A record is judged expired when it is read and cannot be renewed once dead, so correctness never waits for a deletion. Removing the bytes is DynamoDB TTL on the dead_at attribute, which a deployment enables on the table it owns.

Index

Constants

View Source
const DeclaredTable = "popcornweb_session"

DeclaredTable is the name source uses. A deployment maps it onto its own through middleware.dynamo, like any other table.

Variables

This section is empty.

Functions

func Table

func Table(name string) dynamodb.TableDefinition

Table is the definition of the session table. It is handwritten rather than generated: this package is the only reader and writer of the item, so the drift a generated codec closes cannot occur, and generating for one internal type would put a code generation step in the framework's own build.

Types

type Options

type Options struct {
	// Table is the declared table name. Empty means DeclaredTable.
	Table string
	// ConsistentRead makes the first read strongly consistent and removes the
	// retry described on Get. It costs twice the read capacity.
	ConsistentRead bool
	// Now is injectable for tests.
	Now func() time.Time
}

Options configures a store.

type Store

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

Store is the DynamoDB session backend. It implements session.RawStore, so it never sees the application payload type: the host adds that back with session.Typed.

func NewStore

func NewStore(options Options) *Store

NewStore builds a store. It opens nothing: the client comes from the request context, installed by the database/dynamo middleware.

func (*Store) Delete

func (store *Store) Delete(ctx context.Context, keyHash string) error

Delete removes one record. DeleteItem succeeds on an absent key, which is the idempotence the contract asks for.

func (*Store) Get

func (store *Store) Get(ctx context.Context, keyHash string) (session.RawRecord, error)

Get returns the stored record.

The read is eventually consistent, and a miss is retried once with a consistent read. A hit is never re-read, so the common authenticated request pays the cheap read; the case the retry exists for is the false miss right after a login rotation, which a consistent read cannot produce.

func (*Store) Put

func (store *Store) Put(ctx context.Context, keyHash string, record session.RawRecord) error

Put replaces one key. PutItem is atomic per item, so no condition is needed.

func (*Store) Touch

func (store *Store) Touch(ctx context.Context, keyHash string, lastSeenAt, idleExpiresAt time.Time) error

Touch renews an existing record in one conditional request. The condition carries the whole guarantee: the item must exist and still be alive, so no read-then-write window exists for a concurrent delete to fall into.

Jump to

Keyboard shortcuts

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