mutablesession.go

Overview

This file defines the MutableSession type, a core implementation of the session.Session interface within the system. It acts as a wrapper around an existing immutable session.Session instance, providing the ability to mutate session state when supported. The primary purpose of MutableSession is to allow controlled modifications to the session state while delegating immutable session attributes and event handling to the underlying stored session.

The design facilitates session state management where mutability is conditional on the underlying session's state implementation, enabling safe mutation operations and error handling when unsupported. This is critical for managing user-agent interaction sessions, as described in the broader Session Management topic.


Types and Functions

MutableSession struct

type MutableSession struct {
	service       session.Service
	storedSession session.Session
}

NewMutableSession

func NewMutableSession(service session.Service, storedSession session.Session) *MutableSession

Methods on MutableSession

State

func (s *MutableSession) State() session.State

AppName

func (s *MutableSession) AppName() string

UserID

func (s *MutableSession) UserID() string

ID

func (s *MutableSession) ID() string

Events

func (s *MutableSession) Events() session.Events

LastUpdateTime

func (s *MutableSession) LastUpdateTime() time.Time

Session State Operations

Get

func (s *MutableSession) Get(key string) (any, error)

All

func (s *MutableSession) All() iter.Seq2[string, any]

Set

func (s *MutableSession) Set(key string, value any) error

Important Implementation Details


Interactions with Other Components

This file serves as a bridge to enable mutable session manipulations while preserving the original session interface and state management contracts, facilitating flexible session handling workflows, as elaborated in the broader Session Management topic.


Diagram: MutableSession Structure and Method Delegation

classDiagram
class MutableSession {
- service: session.Service
- storedSession: session.Session
+ State()
+ AppName()
+ UserID()
+ ID()
+ Events()
+ LastUpdateTime()
+ Get()
+ All()
+ Set()
}
MutableSession --> session.Session : storedSession
MutableSession --> session.Service : service
MutableSession ..> MutableState : type assertion in Set()

This documentation focuses on the detailed functionality and design of the MutableSession implementation, which is a vital part of session state management in the system. For further details on session lifecycle, state interfaces, and event processing, refer to the Session Management topic.