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 ¶
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.