session

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithSession

func WithSession(ctx context.Context, session *Session) context.Context

WithSession returns a new context derived from ctx that carries the provided session.

Types

type InMemorySessionStore

type InMemorySessionStore struct {
	// contains filtered or unexported fields
}

InMemorySessionStore provides a thread-safe in-memory implementation of SessionStore.

func NewInMemorySessionStore

func NewInMemorySessionStore() *InMemorySessionStore

NewInMemorySessionStore creates a new in-memory session store.

func (*InMemorySessionStore) Create

func (s *InMemorySessionStore) Create() *Session

Create generates a new session with a unique ID and adds it to the store.

func (*InMemorySessionStore) Delete

func (s *InMemorySessionStore) Delete(sessionID SessionID)

Delete removes a session from the store.

func (*InMemorySessionStore) Get

func (s *InMemorySessionStore) Get(sessionID SessionID) (*Session, bool)

Get retrieves a session by its ID.

func (*InMemorySessionStore) Update

func (s *InMemorySessionStore) Update(session *Session)

Update stores the potentially modified session state. For this in-memory store using pointers, changes to the retrieved session are inherently reflected. This method ensures the session exists.

type Session

type Session struct {
	ID    SessionID
	State SessionState
	// contains filtered or unexported fields
}

Session represents a client session.

func GetSessionFromContext

func GetSessionFromContext(ctx context.Context) (*Session, bool)

GetSessionFromContext retrieves the Session stored in the context, if any.

func NewSession

func NewSession() *Session

func (*Session) DeleteData

func (s *Session) DeleteData(key string)

DeleteData removes a key-value pair from the session's state. It is thread-safe.

func (*Session) GetData

func (s *Session) GetData(key string) (interface{}, bool)

GetData retrieves a value from the session's state by key. The boolean return value indicates whether the key was found. It is thread-safe.

func (*Session) SetData

func (s *Session) SetData(key string, value interface{})

SetData stores a key-value pair in the session's state. It is thread-safe.

type SessionID

type SessionID string

type SessionState

type SessionState map[string]interface{}

SessionState holds arbitrary data for a session.

type SessionStore

type SessionStore interface {
	Get(sessionID SessionID) (*Session, bool)
	Create() *Session
	Update(session *Session) // Note: For in-memory, Get returns a pointer, so Update might be implicit.
	Delete(sessionID SessionID)
}

SessionStore defines the interface for managing sessions.

Jump to

Keyboard shortcuts

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