driver

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	// Close closes the session handler.
	Close() error
	// Destroy destroys the session with the given ID. Destroying a missing
	// session is not an error.
	Destroy(id string) error
	// Gc performs garbage collection on the session handler with the given maximum lifetime.
	Gc(maxLifetime int) error
	// Read returns the session data for the given ID. found is false when
	// the session does not exist or has expired; err is reserved for store
	// failures.
	Read(id string) (data string, found bool, err error)
	// Touch refreshes the session's last access time without reading or
	// writing data. found is false when the session does not exist; err is
	// reserved for store failures.
	Touch(id string) (found bool, err error)
	// Write writes the session data associated with the given ID.
	Write(id string, data string) error
}

Driver is the interface for Session handlers.

Read and Touch report a missing (or expired) session via their found return value rather than an error: "session is gone" is a normal outcome that callers may treat as a fresh session, while a non-nil error means the store itself failed and stored data must not be overwritten.

type File

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

File is a session driver that stores each session in its own file.

Concurrent access to the same session is serialized by the Manager's per-session locks, and writes are atomic (temp file + rename), so the driver itself needs no locking.

func NewFile

func NewFile(path string, minutes int) *File

NewFile creates a file driver that stores sessions under path, treating sessions older than minutes as expired. An empty path defaults to a dedicated per-user directory inside os.TempDir() ("sessions-<uid>" on Unix, "sessions" on Windows where the temp directory is per-user already); minutes <= 0 defaults to 120.

func (*File) Close

func (f *File) Close() error

func (*File) Destroy

func (f *File) Destroy(id string) error

func (*File) Gc

func (f *File) Gc(maxLifetime int) error

Gc removes expired session files. Only files that look like session data (32 alphanumeric characters, or leftover temp files from atomic writes) are removed, so a directory shared with other applications stays intact.

func (*File) Read

func (f *File) Read(id string) (string, bool, error)

func (*File) Touch added in v1.4.0

func (f *File) Touch(id string) (bool, error)

func (*File) Write

func (f *File) Write(id string, data string) error

Write persists the session data atomically: the data is written to a temporary file (0600) which is then renamed over the target, so a concurrent Read never observes a partially written session.

Jump to

Keyboard shortcuts

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