sessions

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 1 Imported by: 0

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) Get

func (s *MemorySession) Get(key string) (any, bool)

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) 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() string
	Get(key string) (any, bool)
	Set(key string, value any)
}

type Sessions

type Sessions interface {
	Get(id string) (Session, bool)
	Set(id string, session Session)
	Delete(id string)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL