Documentation
¶
Index ¶
- Constants
- type Encoder
- type Engine
- type EngineProperties
- type FileEngine
- func (e *FileEngine) Enabled() bool
- func (e *FileEngine) GetSession(id string, ctx context.Context) (Session, error)
- func (e *FileEngine) Name() string
- func (e *FileEngine) NewId() string
- func (e *FileEngine) Purge() error
- func (e *FileEngine) Read(id string, v any) error
- func (e *FileEngine) SessionNotExists(id string) (bool, error)
- func (e *FileEngine) SetEnabled(enabled bool)
- func (e *FileEngine) SetName(n string)
- func (e *FileEngine) Start(_ context.Context) error
- func (e *FileEngine) Stop() error
- func (e *FileEngine) Store(id string, v any) error
- func (e *FileEngine) StoreSession(id string, s Session) error
- type JsonEncoder
- type RedisEngine
- func (e *RedisEngine) Enabled() bool
- func (e *RedisEngine) GetSession(id string, ctx context.Context) (Session, error)
- func (e *RedisEngine) Name() string
- func (e *RedisEngine) NewId() string
- func (e *RedisEngine) Purge() error
- func (e *RedisEngine) Read(id string, v any) error
- func (e *RedisEngine) SessionNotExists(id string) (bool, error)
- func (e *RedisEngine) SetEnabled(enabled bool)
- func (e *RedisEngine) SetName(n string)
- func (e *RedisEngine) Start(ctx context.Context) error
- func (e *RedisEngine) Stop() error
- func (e *RedisEngine) Store(id string, v any) error
- func (e *RedisEngine) StoreSession(id string, s Session) error
- type Session
Constants ¶
const ( // ContextEngValue is the context key for storing the session Engine. ContextEngValue = "HTTPOKSESSCTXENGVALUE" // ContextSessValue is the context key for storing the session data. ContextSessValue = "HTTPOKSESSCTXSESSVALUE" // DefaultName is the default name for session cookies. DefaultName = "HTTPOKSESSID" // DefaultPrefix is the default prefix used for session keys. DefaultPrefix = "httpok:session" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine interface {
Enabled() bool
NewId() string
SetEnabled(bool)
// TODO: PurgeSession(id string)
Name() string
SetName(string)
Read(string, any) error
Start(context.Context) error
Stop() error
Store(string, any) error
Purge() error
GetSession(string, context.Context) (Session, error)
SessionNotExists(string) (bool, error)
StoreSession(string, Session) error
}
Engine defines the interface for session management.
type EngineProperties ¶
type EngineProperties struct {
AgeLimit time.Duration
Encoder
logger.Logger
// TODO: Add this to the interface
Prefix string
PurgeDuration time.Duration
// contains filtered or unexported fields
}
EngineProperties contains common properties for session engines.
type FileEngine ¶
type FileEngine struct {
EngineProperties
Dir string
}
FileEngine implements the Engine interface for file-based session storage.
func NewFileEngine ¶
func NewFileEngine() *FileEngine
NewFileEngine creates and returns a new FileEngine with default settings.
func (*FileEngine) Enabled ¶
func (e *FileEngine) Enabled() bool
Enabled returns whether the session management is enabled.
func (*FileEngine) GetSession ¶
GetSession retrieves a session from file storage based on the given ID.
func (*FileEngine) Name ¶
func (e *FileEngine) Name() string
Name returns the name of the session engine.
func (*FileEngine) NewId ¶
func (e *FileEngine) NewId() string
NewId generates and returns a new session ID.
func (*FileEngine) Purge ¶
func (e *FileEngine) Purge() error
Purge removes expired sessions from file storage.
func (*FileEngine) Read ¶
func (e *FileEngine) Read(id string, v any) error
Read retrieves and decodes session data from file storage.
func (*FileEngine) SessionNotExists ¶
func (e *FileEngine) SessionNotExists(id string) (bool, error)
SessionNotExists checks if a session with the given ID does not exist in file storage.
func (*FileEngine) SetEnabled ¶
func (e *FileEngine) SetEnabled(enabled bool)
SetEnabled sets the enabled status of the session management.
func (*FileEngine) SetName ¶
func (e *FileEngine) SetName(n string)
SetName sets the name of the session engine.
func (*FileEngine) Start ¶
func (e *FileEngine) Start(_ context.Context) error
Start initializes the directory for session storage.
func (*FileEngine) Stop ¶
func (e *FileEngine) Stop() error
Stop is a placeholder for stopping the session engine, currently does nothing.
func (*FileEngine) Store ¶
func (e *FileEngine) Store(id string, v any) error
Store saves session data to file storage.
func (*FileEngine) StoreSession ¶
func (e *FileEngine) StoreSession(id string, s Session) error
StoreSession saves the session data back to file storage.
type JsonEncoder ¶
type JsonEncoder struct {
}
JsonEncoder implements the Encoder interface using JSON serialization.
type RedisEngine ¶
type RedisEngine struct {
EngineProperties
// contains filtered or unexported fields
}
RedisEngine is the implementation of session management using Redis.
func NewRedisEngine ¶
func NewRedisEngine() (*RedisEngine, error)
NewRedisEngine creates and returns a new RedisEngine with default settings.
func (*RedisEngine) Enabled ¶
func (e *RedisEngine) Enabled() bool
Enabled returns whether the session management is enabled.
func (*RedisEngine) GetSession ¶
GetSession retrieves a session from Redis based on the given ID.
func (*RedisEngine) Name ¶
func (e *RedisEngine) Name() string
Name returns the name of the session engine.
func (*RedisEngine) NewId ¶
func (e *RedisEngine) NewId() string
NewId generates and returns a new session ID.
func (*RedisEngine) Purge ¶
func (e *RedisEngine) Purge() error
Purge removes expired sessions from Redis.
func (*RedisEngine) Read ¶
func (e *RedisEngine) Read(id string, v any) error
Read retrieves and decodes session data from Redis.
func (*RedisEngine) SessionNotExists ¶
func (e *RedisEngine) SessionNotExists(id string) (bool, error)
SessionNotExists checks if a session with the given ID does not exist in Redis.
func (*RedisEngine) SetEnabled ¶
func (e *RedisEngine) SetEnabled(enabled bool)
SetEnabled sets the enabled status of the session management.
func (*RedisEngine) SetName ¶
func (e *RedisEngine) SetName(n string)
SetName sets the name of the session engine.
func (*RedisEngine) Start ¶
func (e *RedisEngine) Start(ctx context.Context) error
Start initializes the connection to Redis.
func (*RedisEngine) Stop ¶
func (e *RedisEngine) Stop() error
Stop is a placeholder for stopping the session engine, currently does nothing.
func (*RedisEngine) Store ¶
func (e *RedisEngine) Store(id string, v any) error
Store saves session data to Redis.
func (*RedisEngine) StoreSession ¶
func (e *RedisEngine) StoreSession(id string, s Session) error
StoreSession saves the session data back to Redis.
type Session ¶
type Session struct {
Id string
Changed bool
Ctx context.Context
Data map[string]any
Destroyed bool
Params any
}
Session represents a user session with data storage capabilities.
func SessionFromContext ¶
SessionFromContext retrieves the session from the context.
func (*Session) Clear ¶
func (s *Session) Clear()
Clear removes all data from the session and marks it as changed.