Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemorySession ¶
type MemorySession struct {
// contains filtered or unexported fields
}
MemorySession represents an in-memory session with a unique identifier, a map to store session data, and a read-write mutex for concurrent access control.
func NewMemorySession ¶
func NewMemorySession(id string) *MemorySession
NewMemorySession creates a new MemorySession with the given id. It initializes the session data as an empty map and sets up a read-write mutex for concurrent access.
Parameters:
- id: A string representing the unique identifier for the session.
Returns:
- A pointer to a newly created MemorySession instance.
func (*MemorySession) Exists ¶ added in v0.0.4
func (s *MemorySession) Exists(key string) bool
Exists checks if the given key exists in the memory session. It returns a boolean indicating whether the key is present in the session.
func (*MemorySession) Get ¶
func (s *MemorySession) Get(key string) any
Get retrieves the value associated with the given key from the memory session. It returns the value and a boolean indicating whether the key was found. The method is thread-safe, using a read lock to ensure concurrent access.
func (*MemorySession) Id ¶
func (s *MemorySession) Id() string
Id returns the unique identifier of the MemorySession. It retrieves the session's ID as a string.
func (*MemorySession) Set ¶
func (s *MemorySession) Set(key string, value any)
Set stores a key-value pair in the memory session. It locks the session to ensure thread safety before setting the value and unlocks it afterward.
Parameters:
- key: The key under which the value will be stored.
- value: The value to be stored, which can be of any type.
type MemorySessions ¶
type MemorySessions struct {
// contains filtered or unexported fields
}
MemorySessions is a struct that manages a collection of in-memory sessions. It contains a map of session IDs to MemorySession pointers and a read-write mutex to ensure thread-safe access to the sessions map.
func NewMemorySessions ¶
func NewMemorySessions() *MemorySessions
NewMemorySessions creates and returns a new instance of MemorySessions. It initializes the sessions map and the read-write mutex.
func (*MemorySessions) Delete ¶
func (s *MemorySessions) Delete(id string)
Delete removes a session from the memory store by its ID. It locks the session map to ensure thread safety during the deletion process.
Parameters:
id (string): The ID of the session to be deleted.
func (*MemorySessions) Get ¶
func (s *MemorySessions) Get(id string) (Session, bool)
Get retrieves a session from the memory store by its ID. It returns the session and a boolean indicating whether the session was found. The method is thread-safe, using a read lock to ensure concurrent access.
func (*MemorySessions) New ¶ added in v0.0.5
func (s *MemorySessions) New() Session
New creates a new MemorySession with a unique identifier. It generates a new UUID string to use as the session ID.
Returns:
- A pointer to a newly created MemorySession instance.
func (*MemorySessions) Set ¶
func (s *MemorySessions) Set(id string, session Session)
Set stores a session in the MemorySessions map with the given id. It locks the mutex to ensure thread safety before modifying the map.
Parameters:
- id: A string representing the session ID.
- session: A Session interface that will be type asserted to *MemorySession.
type Session ¶
type Session interface {
// Id returns the unique identifier for the session.
Id() string
// Get retrieves the value associated with the given key.
// Returns the value or nil if the key was not found.
Get(key string) any
// Set stores the given value associated with the key.
Set(key string, value any)
// Check if the key exists in the session.
Exists(key string) bool
}
Session represents a user session with methods to manage session data. It provides an interface for retrieving and storing key-value pairs.
Methods:
- Id() string: Returns the unique identifier for the session.
- Get(key string) (any, bool): Retrieves the value associated with the given key. Returns the value and a boolean indicating whether the key was found.
- Set(key string, value any): Stores the given value associated with the key.
type Sessions ¶
type Sessions interface {
// Get retrieves a session by its ID.
// Returns the session and a boolean indicating whether the session was found.
Get(id string) (Session, bool)
// Set stores a session with the given ID.
Set(id string, session Session)
// Delete deletes the session associated with the given ID.
Delete(id string)
// Create a new session with a new ID.
New() Session
}
Sessions defines an interface for managing user sessions. It provides methods to retrieve, store, and delete sessions by their unique identifier.
Methods:
- Get(id string) (Session, bool): Retrieves a session by its ID. Returns the session is found.
- Set(id string, session Session): Stores a session with the given ID.
- Delete(id string): Deletes the session associated with the given ID.