session

package
v0.0.0-...-f98e9bb Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SESSION_LIFETIME = 1 * time.Hour
	GC_PERIOD        = 2 * time.Minute
)

Variables

This section is empty.

Functions

func Module

func Module(module common.Module)

func NewDatabase

func NewDatabase() (database.Database, common.Closer, error)

Types

type Service

type Service interface {
	NewSession(ctx context.Context) (Session, error)
	LookupById(ctx context.Context, id *common.Ulid) (Session, error)
	Authenticate(session Session, identityId *common.Ulid, credentialId *common.Ulid) (Session, error)
	DeleteSession(session Session) error
	PutValue(session Session, key string, value fmt.Stringer) error
}

func NewService

func NewService(repo *SessionRepository) (Service, common.ContextValues)

type Session

type Session interface {
	context.Context

	Id() *common.Ulid
	RequestId() *common.Ulid
	Expires() *time.Time
	ActorId() *common.Ulid
	CredentialId() *common.Ulid

	// NOTE: This function does not check if a session is expired.
	// It only checks for existence of the required authentication fields.
	Authenticated() bool
	Expired() bool
	LocalMemberships() []*common.Ulid
	MemberOf(localId *common.Ulid) bool

	NewRequest() Session
	WithMemberships(locals []*common.Ulid) Session

	Values() common.M
	// contains filtered or unexported methods
}

func FromContext

func FromContext(ctx context.Context) Session

type SessionRecord

type SessionRecord struct {
	Id         string
	Expires    *time.Time
	Identity   *string
	Credential *string
}

type SessionRepository

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

func NewRepo

func NewRepo(db database.Database) *SessionRepository

func (*SessionRepository) AssignIdentity

func (repo *SessionRepository) AssignIdentity(
	tx *sql.Tx,
	sessionId string,
	identityId string,
	expires time.Time,
	credentialId string,
) (*SessionRecord, error)

func (*SessionRepository) DeleteSessionById

func (repo *SessionRepository) DeleteSessionById(
	tx *sql.Tx,
	sessionId string,
) error

func (*SessionRepository) DeleteSessionsByExpiresAfter

func (repo *SessionRepository) DeleteSessionsByExpiresAfter(tx *sql.Tx, expiration time.Time) error

func (*SessionRepository) DeleteValue

func (repo *SessionRepository) DeleteValue(
	tx *sql.Tx,
	sessionId string,
	key string,
) error

func (*SessionRepository) FindAllSessionValues

func (repo *SessionRepository) FindAllSessionValues(tx *sql.Tx, sessionId string) ([]*SessionValueRecord, error)

func (*SessionRepository) FindById

func (repo *SessionRepository) FindById(tx *sql.Tx, sessionId string) (*SessionRecord, error)

func (*SessionRepository) GetValue

func (repo *SessionRepository) GetValue(
	tx *sql.Tx,
	sessionId string,
	key string,
) (*SessionValueRecord, error)

func (*SessionRepository) NewSession

func (repo *SessionRepository) NewSession(tx *sql.Tx, expires *time.Time) (*SessionRecord, error)

func (*SessionRepository) SetValue

func (repo *SessionRepository) SetValue(
	tx *sql.Tx,
	sessionId string,
	key string,
	value string,
) (*SessionValueRecord, error)

func (*SessionRepository) UpdateExpiration

func (repo *SessionRepository) UpdateExpiration(
	tx *sql.Tx,
	sessionId string,
	expires time.Time,
) (*SessionRecord, error)

type SessionValueRecord

type SessionValueRecord struct {
	Id      string
	Session string
	Key     string
	Value   *string
}

Jump to

Keyboard shortcuts

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