store

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store defines the interface between stateful frontends and their session storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("session not found")
	ErrConflict = errors.New("session changed")
)

Functions

This section is empty.

Types

type Record

type Record struct {
	// Expires is the time after which the session is no longer valid.
	Expires time.Time
	// Partition identifies the frontend of the session.
	Partition string
	// Subject is the sub claim of the user.
	Subject string
	// SID is the sid claim of the provider session. It may be empty.
	SID string
	// Data is the session, encrypted by the frontend.
	Data []byte
	// Generation counts the changes of the session tokens. A record never replaces a record with a greater
	// generation.
	Generation int64
}

Record is a session kept by a Store.

type Store

type Store interface {
	// Load returns the record of the session, or [ErrNotFound] if it does not exist or has expired.
	Load(ctx context.Context, id string) (Record, error)
	// Create stores the record of a new session.
	Create(ctx context.Context, id string, r Record) error
	// Update replaces the record of an existing session, or returns [ErrNotFound] if it does not exist or has
	// expired. It returns [ErrConflict] without replacing the record if the stored record has a greater generation.
	Update(ctx context.Context, id string, r Record) error
	// Delete deletes the session. Deleting a session that does not exist is not an error.
	Delete(ctx context.Context, id string) error
	// DeleteBy deletes the sessions of the partition that belong to the subject, restricted to the sid when it is not
	// empty, and returns them by id. An empty subject matches any subject. It may return an error with a non-empty map.
	DeleteBy(ctx context.Context, partition, subject, sid string) (map[string]Record, error)
}

Store keeps the sessions of stateful frontends. A Store must be safe for concurrent use.

Directories

Path Synopsis
Package memory provides a store.Store that keeps the sessions in memory.
Package memory provides a store.Store that keeps the sessions in memory.
redis module
Package storetest tests implementations of store.Store.
Package storetest tests implementations of store.Store.

Jump to

Keyboard shortcuts

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