session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirPerm  os.FileMode = 0o700 // Directory permission for session store
	FilePerm os.FileMode = 0o600 // File permission for session files
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStore

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

FileStore is a file-backed implementation of Store. Each session is stored as {id}.json in a directory. It is safe for concurrent use.

func NewFileStore

func NewFileStore(dir string) (*FileStore, error)

NewFileStore creates a new file-backed session store in the given directory. The directory is created if it does not exist.

func (*FileStore) Create

func (f *FileStore) Create(_ context.Context, meta schema.SessionMeta) (*schema.Session, error)

Create creates a new session with a unique ID, writes it to disk, and returns it.

func (*FileStore) Delete

func (f *FileStore) Delete(_ context.Context, id string) error

Delete removes a session file by ID.

func (*FileStore) Get

func (f *FileStore) Get(_ context.Context, id string) (*schema.Session, error)

Get retrieves a session by ID from disk.

func (*FileStore) List

List returns sessions from disk, ordered by last modified time (most recent first), with pagination support.

func (*FileStore) Update

func (f *FileStore) Update(_ context.Context, id string, meta schema.SessionMeta) (*schema.Session, error)

Update applies non-zero fields from meta to the session identified by id, persists the result to disk, and returns the updated session.

func (*FileStore) Write

func (f *FileStore) Write(s *schema.Session) error

Write persists a session's current state to disk. This is called after mutations (e.g. Append) to keep the file in sync.

type MemoryStore

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

MemoryStore is an in-memory implementation of Store. It is safe for concurrent use.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates a new empty in-memory session store.

func (*MemoryStore) Create

Create creates a new session with a unique ID and returns it.

func (*MemoryStore) Delete

func (m *MemoryStore) Delete(_ context.Context, id string) error

Delete removes a session by ID.

func (*MemoryStore) Get

func (m *MemoryStore) Get(_ context.Context, id string) (*schema.Session, error)

Get retrieves a session by ID.

func (*MemoryStore) List

List returns sessions, ordered by last modified time (most recent first), with pagination support.

func (*MemoryStore) Update

func (m *MemoryStore) Update(_ context.Context, id string, meta schema.SessionMeta) (*schema.Session, error)

Update applies non-zero fields from meta to the session identified by id.

func (*MemoryStore) Write

func (m *MemoryStore) Write(_ *schema.Session) error

Write is a no-op for the memory store since sessions are held as pointers in memory and mutations are visible immediately.

Jump to

Keyboard shortcuts

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