Documentation
¶
Index ¶
- type CookieStore
- type DBStore
- type FileStore
- type Manager
- func (m *Manager) Destroy(w http.ResponseWriter, id string) error
- func (m *Manager) Flash(data map[string]interface{}, key string, value interface{})
- func (m *Manager) FlashErrors(data map[string]interface{}, errors map[string][]string)
- func (m *Manager) FlashOldInput(data map[string]interface{}, input map[string]string)
- func (m *Manager) GetFlash(data map[string]interface{}, key string) (interface{}, bool)
- func (m *Manager) Save(w http.ResponseWriter, id string, data map[string]interface{}) error
- func (m *Manager) Start(r *http.Request) (string, map[string]interface{}, error)
- type MemoryStore
- type RedisStore
- type SessionRecord
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CookieStore ¶
type CookieStore struct {
Key []byte
// contains filtered or unexported fields
}
CookieStore stores session data encrypted in the cookie value itself. Requires a 32-byte key (AES-256-GCM).
func NewCookieStore ¶
func NewCookieStore(key []byte) (*CookieStore, error)
NewCookieStore creates a cookie-based session store with the given AES-256 key.
func (*CookieStore) Destroy ¶
func (s *CookieStore) Destroy(id string) error
type FileStore ¶
type FileStore struct {
Path string
}
FileStore stores one JSON file per session in the configured directory.
type Manager ¶
type Manager struct {
Store Store
CookieName string
Lifetime time.Duration
Path string
Domain string
Secure bool
HTTPOnly bool
SameSite http.SameSite
}
Manager ties together the store, cookie handling, and ID generation.
func NewManager ¶
NewManager creates a session manager from environment config.
func (*Manager) Destroy ¶
func (m *Manager) Destroy(w http.ResponseWriter, id string) error
Destroy removes a session and clears the cookie.
func (*Manager) Flash ¶
Flash writes a flash message that will be available on the next request only.
func (*Manager) FlashErrors ¶
FlashErrors stores validation errors for the next request.
func (*Manager) FlashOldInput ¶
FlashOldInput stores form input for re-populating after validation failure.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore stores sessions in memory. For development and testing only.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new in-memory session store.
func (*MemoryStore) Destroy ¶
func (s *MemoryStore) Destroy(id string) error
type RedisStore ¶
RedisStore stores sessions in Redis.
func NewRedisStore ¶
func NewRedisStore(client *redis.Client, prefix string) *RedisStore
NewRedisStore creates a Redis-backed session store from the given client.
func (*RedisStore) Destroy ¶
func (s *RedisStore) Destroy(id string) error
type SessionRecord ¶
type SessionRecord struct {
ID string `gorm:"primaryKey;size:255"`
Data string `gorm:"type:text;not null"`
UserID *uint `gorm:"index"`
IPAddress *string `gorm:"size:45"`
UserAgent *string `gorm:"type:text"`
LastActive time.Time `gorm:"autoUpdateTime"`
CreatedAt time.Time
}
SessionRecord represents a row in the sessions table.
func (SessionRecord) TableName ¶
func (SessionRecord) TableName() string
TableName returns the database table name.
type Store ¶
type Store interface {
// Read returns session data for the given ID, or empty map if not found.
Read(id string) (map[string]interface{}, error)
// Write persists session data with the given ID and lifetime.
Write(id string, data map[string]interface{}, lifetime time.Duration) error
// Destroy removes a session by ID.
Destroy(id string) error
// GC removes sessions older than the given max lifetime.
GC(maxLifetime time.Duration) error
}
Store defines the contract every session backend must satisfy.