Documentation ¶
Index ¶
- type Config
- type Session
- type SessionManager
- func (sm *SessionManager) CreateSession(ctx context.Context, userID uuid.UUID, attributes map[string]interface{}) (uuid.UUID, error)
- func (sm *SessionManager) DeleteAllUserSessions(ctx context.Context, userID uuid.UUID) error
- func (sm *SessionManager) DeleteSession(ctx context.Context, sessionID uuid.UUID) error
- func (sm *SessionManager) GetSession(ctx context.Context, sessionID uuid.UUID, updateSessionAccess bool) (*Session, error)
- func (sm *SessionManager) Shutdown(ctx context.Context) error
- func (sm *SessionManager) UpdateSession(ctx context.Context, session *Session) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // MaxSessions is the maximum number of concurrent sessions allowed per user. // When this limit is reached, the oldest session will be removed. MaxSessions int `json:"maxSessions"` // MaxAttributeLength is the maximum length (in bytes) allowed for a single session attribute value. MaxAttributeLength int `json:"maxAttributeLength"` // SessionExpiration is the duration after which a session expires if not accessed. SessionExpiration time.Duration `json:"sessionExpiration"` // InactivityDuration is the duration of inactivity after which a session is considered expired. InactivityDuration time.Duration `json:"inactivityDuration"` // CleanupInterval is the time interval between cleanup operations for expired sessions. CleanupInterval time.Duration `json:"cleanupInterval"` // CacheSize is the maximum number of sessions to keep in the in-memory cache. CacheSize int `json:"cacheSize"` // TablePrefix is the prefix to be used for all database tables created by the SessionManager. // This allows multiple SessionManager instances to coexist in the same database. TablePrefix string `json:"tablePrefix"` // SchemaName is the name of the PostgreSQL schema to use for session tables. // If empty, the default schema (usually "public") will be used. SchemaName string `json:"schemaName"` // CreateSchemaIfMissing, if true, will create the specified schema if it doesn't exist. CreateSchemaIfMissing bool `json:"createSchemaIfMissing"` // LastAccessUpdateInterval is the time interval between batch updates of session last access times. LastAccessUpdateInterval time.Duration `json:"lastAccessUpdateInterval"` // LastAccessUpdateBatchSize is the maximum number of sessions to update in a single batch operation. LastAccessUpdateBatchSize int `json:"lastAccessUpdateBatchSize"` }
Config holds the configuration options for the SessionManager.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config struct with default values.
type Session ¶
type Session struct { ID uuid.UUID `db:"id"` UserID uuid.UUID `db:"user_id"` LastAccessed time.Time `db:"last_accessed"` ExpiresAt time.Time `db:"expires_at"` UpdatedAt time.Time `db:"updated_at"` // contains filtered or unexported fields }
func (*Session) GetAttribute ¶
GetAttribute returns the value of a specific attribute.
func (*Session) GetAttributes ¶
GetAttributes returns all attributes of the session.
func (*Session) UpdateAttribute ¶
UpdateAttribute updates or adds an attribute to the session.
type SessionManager ¶
type SessionManager struct { Config *Config // contains filtered or unexported fields }
SessionManager manages sessions in a PostgreSQL database with caching capabilities.
func NewSessionManager ¶
func NewSessionManager(cfg *Config, pgxConnectionString string) (*SessionManager, error)
NewSessionManager creates a new SessionManager with the given configuration and connection string.
func (*SessionManager) CreateSession ¶
func (sm *SessionManager) CreateSession(ctx context.Context, userID uuid.UUID, attributes map[string]interface{}) (uuid.UUID, error)
CreateSession creates a new session for the given user with the provided attributes.
func (*SessionManager) DeleteAllUserSessions ¶
DeleteAllUserSessions deletes all sessions for a given user.
func (*SessionManager) DeleteSession ¶
DeleteSession deletes a session by its ID.
func (*SessionManager) GetSession ¶
func (sm *SessionManager) GetSession(ctx context.Context, sessionID uuid.UUID, updateSessionAccess bool) (*Session, error)
GetSession retrieves a session by its ID and optionally updates its last access time.
func (*SessionManager) Shutdown ¶
func (sm *SessionManager) Shutdown(ctx context.Context) error
Shutdown gracefully shuts down the SessionManager.
func (*SessionManager) UpdateSession ¶
func (sm *SessionManager) UpdateSession(ctx context.Context, session *Session) error
UpdateSession updates the session in the database with any changes made to its attributes.