acctctx

package
v0.0.0-...-d4212fa Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package acctctx provides type-safe access to account-related values stored in the context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Account

func Account(ctx context.Context) *accounts.Account

Account returns the account stored in context or nil if there is none.

func ReplaceSessionData

func ReplaceSessionData(ctx context.Context, p any) error

ReplaceSessionData replaces the data associated with the current session with the JSON-marshaled version of p, and marks the session data as dirty. It always assumes that the data changed when this function is called.

func ResetSession

func ResetSession(ctx context.Context, ssnID string, ssnData json.RawMessage)

ResetSession updates an existing context session in-place with the provided ssnID and ssnData, marking the data as unmodified. It should be used when the session id changes inside the handler wrapped by the Session middleware (e.g. after a login, going from anonymous to authenticated, or the reverse after a logout or a delete account).

As a special case, if ssnData is nil or empty slice, it will be stored as JSON "null".

func Session

func Session(ctx context.Context) (ssnID string, data json.RawMessage, dirty bool)

Session returns the current session id and its associated data, along with a boolean indicating if the data is dirty (if any changes were made since the call to WithSession or ResetSession).

func SessionID

func SessionID(ctx context.Context) string

SessionID returns the session ID stored in the context or an empty string if there is none.

func WithAccount

func WithAccount(ctx context.Context, acct *accounts.Account) context.Context

WithAccount returns a context that holds the specified account. Typically this is the currently authenticated account.

func WithSession

func WithSession(ctx context.Context, ssnID string, ssnData json.RawMessage) context.Context

WithSession returns a context that holds the specified session information. Unlike ResetSession, WithSession always stores a new session entry in the context. It should be used for the initial set of the session, typically called automatically by the Session middleware. An empty ssnID indicates that a new anonymous session should be created to store the data when the Session middleware exits.

As a special case, if ssnData is nil or empty slice, it will be stored as JSON "null".

Types

This section is empty.

Jump to

Keyboard shortcuts

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