Documentation
¶
Index ¶
- func GenerateKey() ([]byte, error)
- type ArrayDriver
- type CookieDriver
- type DatabaseDriver
- type EncryptedStore
- type EnhancedCookieDriver
- func (d *EnhancedCookieDriver) Destroy(id string) error
- func (d *EnhancedCookieDriver) FromJSON(id, jsonStr string) error
- func (d *EnhancedCookieDriver) GetSessionCount() int
- func (d *EnhancedCookieDriver) PurgeExpired(maxAge time.Duration) int
- func (d *EnhancedCookieDriver) Read(id string) (map[string]any, error)
- func (d *EnhancedCookieDriver) ToJSON(id string) (string, error)
- func (d *EnhancedCookieDriver) Write(id string, data map[string]any) error
- type FileDriver
- type Manager
- func (m *Manager) All() map[string]any
- func (m *Manager) Flash(key string, value any)
- func (m *Manager) FlashInput(input map[string]any)
- func (m *Manager) Flush()
- func (m *Manager) Forget(key string)
- func (m *Manager) Get(key string) any
- func (m *Manager) Has(key string) bool
- func (m *Manager) ID() string
- func (m *Manager) Intended(defaultURL ...string) string
- func (m *Manager) Keep(keys ...string)
- func (m *Manager) Old(key string, defaultValue any) any
- func (m *Manager) PreviousURL() string
- func (m *Manager) Pull(key string, defaultValue any) any
- func (m *Manager) Put(key string, value any)
- func (m *Manager) Reflash()
- func (m *Manager) Regenerate() error
- func (m *Manager) Save() error
- func (m *Manager) SetIntendedURL(url string)
- func (m *Manager) SetPreviousURL(url string)
- func (m *Manager) Start() error
- type RedisStore
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
GenerateKey generates a random 32-byte encryption key.
Types ¶
type ArrayDriver ¶
type ArrayDriver struct {
// contains filtered or unexported fields
}
ArrayDriver is an in-memory session driver for testing.
func NewArrayDriver ¶
func NewArrayDriver() *ArrayDriver
NewArrayDriver creates a new in-memory session driver.
func (*ArrayDriver) Count ¶
func (d *ArrayDriver) Count() int
Count returns the number of active sessions.
func (*ArrayDriver) Destroy ¶
func (d *ArrayDriver) Destroy(id string) error
func (*ArrayDriver) Flush ¶
func (d *ArrayDriver) Flush()
Flush removes all sessions (useful in testing).
type CookieDriver ¶
type CookieDriver struct {
}
CookieDriver implements the session.Store interface by storing payloads in cookies. Note: In a real implementation, this requires access to the HTTP Request/Response writers to set the cookie. For the architecture of GoW, the Store interface abstracts reading/writing, so a Cookie driver needs contextual access or relies on the Manager mapping it correctly.
func NewCookieDriver ¶
func NewCookieDriver() *CookieDriver
NewCookieDriver creates a new CookieDriver.
func (*CookieDriver) Destroy ¶
func (d *CookieDriver) Destroy(id string) error
type DatabaseDriver ¶
type DatabaseDriver struct {
// contains filtered or unexported fields
}
DatabaseDriver implements session storage using a database table.
func NewDatabaseDriver ¶
func NewDatabaseDriver(db *sql.DB) *DatabaseDriver
NewDatabaseDriver creates a new database session driver.
func (*DatabaseDriver) Destroy ¶
func (d *DatabaseDriver) Destroy(id string) error
Destroy removes a session from the database.
func (*DatabaseDriver) GarbageCollect ¶
func (d *DatabaseDriver) GarbageCollect(maxLifetime time.Duration) error
GarbageCollect removes expired sessions.
type EncryptedStore ¶
type EncryptedStore struct {
// contains filtered or unexported fields
}
EncryptedStore wraps a Store with AES-GCM encryption.
func NewEncryptedStore ¶
func NewEncryptedStore(store Store, key []byte) (*EncryptedStore, error)
NewEncryptedStore creates a new encrypted session store. The key must be 16, 24, or 32 bytes for AES-128, AES-192, or AES-256.
func (*EncryptedStore) Destroy ¶
func (e *EncryptedStore) Destroy(id string) error
type EnhancedCookieDriver ¶
type EnhancedCookieDriver struct {
// contains filtered or unexported fields
}
EnhancedCookieDriver implements cookie-based session storage with encryption.
func NewEnhancedCookieDriver ¶
func NewEnhancedCookieDriver(secret []byte) *EnhancedCookieDriver
NewEnhancedCookieDriver creates a new enhanced cookie driver.
func (*EnhancedCookieDriver) Destroy ¶
func (d *EnhancedCookieDriver) Destroy(id string) error
Destroy removes a session.
func (*EnhancedCookieDriver) FromJSON ¶
func (d *EnhancedCookieDriver) FromJSON(id, jsonStr string) error
FromJSON deserializes session data from JSON cookie value.
func (*EnhancedCookieDriver) GetSessionCount ¶
func (d *EnhancedCookieDriver) GetSessionCount() int
GetSessionCount returns the number of active sessions.
func (*EnhancedCookieDriver) PurgeExpired ¶
func (d *EnhancedCookieDriver) PurgeExpired(maxAge time.Duration) int
PurgeExpired removes sessions older than the given duration.
func (*EnhancedCookieDriver) Read ¶
func (d *EnhancedCookieDriver) Read(id string) (map[string]any, error)
Read loads session data from the in-memory store (simulating cookie decoding).
type FileDriver ¶
type FileDriver struct {
Path string
}
FileDriver implements the session.Store interface using local files.
func NewFileDriver ¶
func NewFileDriver(path string) *FileDriver
NewFileDriver creates a new FileDriver.
func (*FileDriver) Destroy ¶
func (d *FileDriver) Destroy(id string) error
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the current session state.
func NewManager ¶
NewManager creates a new Session Manager.
func (*Manager) Flash ¶
Flash stores a value in the session that will be available for the next request.
func (*Manager) FlashInput ¶
FlashInput flashes the current request input to the session.
func (*Manager) Intended ¶
Intended stores the intended URL the user was trying to access. After login, call Intended() to get the stored URL and redirect there.
func (*Manager) PreviousURL ¶
PreviousURL stores the URL the user came from (typically set by middleware).
func (*Manager) Reflash ¶
func (m *Manager) Reflash()
Reflash keeps all current flash data for an additional request.
func (*Manager) Regenerate ¶
Regenerate generates a new session ID and migrates the data.
func (*Manager) SetIntendedURL ¶
SetIntendedURL stores the intended URL for post-login redirect.
func (*Manager) SetPreviousURL ¶
SetPreviousURL stores the previous URL in the session.
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore is a session driver backed by Redis.
func NewRedisStore ¶
NewRedisStore creates a new Redis session store.
func (*RedisStore) Destroy ¶
func (s *RedisStore) Destroy(id string) error
Destroy removes the session data by ID.
type Store ¶
type Store interface {
// Read retrieves the session data by ID.
Read(id string) (map[string]any, error)
// Write saves the session data by ID.
Write(id string, data map[string]any) error
// Destroy removes the session data by ID.
Destroy(id string) error
}
Store represents a session storage driver.