Code documentation
This commit is contained in:
@@ -1,3 +1,35 @@
|
||||
// Package session
|
||||
// Path: /internal/platform/session
|
||||
// File: session.go
|
||||
//
|
||||
// Purpose
|
||||
// Initialize and configure the SCS (Server-Side Sessions) session manager
|
||||
// based on application configuration. Controls session lifetime, idle timeout,
|
||||
// cookie policy, and security posture.
|
||||
//
|
||||
// Responsibilities (as implemented here)
|
||||
// 1) Create SCS session manager used globally via bootstrap.
|
||||
// 2) Parse session lifetime + idle timeout from configuration.
|
||||
// 3) Apply secure cookie settings (HttpOnly, SameSite, Secure if production).
|
||||
// 4) Provide sensible defaults if configuration is invalid.
|
||||
//
|
||||
// Design notes
|
||||
// - SCS stores session data server-side (DB, file, mem, etc. — backend not set here).
|
||||
// - Cookie lifespan is enforced server-side (not just client expiry).
|
||||
// - Secure flag toggled via cfg.HttpServer.ProductionMode.
|
||||
// - Defaults keep application functional even if config is incomplete.
|
||||
//
|
||||
// TODOs (observations from current implementation)
|
||||
// - Add structured validation + error logging for invalid duration strings.
|
||||
// - Move secure cookie flag to config for more granular environment control.
|
||||
// - Consider enabling:
|
||||
// • Cookie.Persist (for "keep me logged in" flows)
|
||||
// • Cookie.SameSite = StrictMode by default
|
||||
// - Potentially expose SCS store configuration here (DB-backed sessions).
|
||||
//
|
||||
// Change log
|
||||
// [2025-10-29] Documentation aligned with final session architecture.
|
||||
|
||||
package session
|
||||
|
||||
import (
|
||||
@@ -9,6 +41,8 @@ import (
|
||||
"github.com/alexedwards/scs/v2"
|
||||
)
|
||||
|
||||
// New constructs a new SCS SessionManager using values from Config,
|
||||
// falling back to secure defaults if configuration is missing/invalid.
|
||||
func New(cfg config.Config) *scs.SessionManager {
|
||||
s := scs.New()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user