Documentation
¶
Overview ¶
Package session implements Session\Manager and the Session\Storage\* family: an HTTP-only cookie carrying an opaque, randomly generated session ID, and the storage the data behind that ID lives in. Memory storage lasts as long as the process; disk storage is a file per session under a directory the host chooses, and prunes by modification time.
A manager wraps whichever storage it is given for tracing, so a request's trace shows which backend it paid for and whether the session was there. The session ID is never recorded: it is the credential in the cookie.
It is wired in by importing it; stdlib/imports.go does that.
Index ¶
- func Register(rt *runner.Runtime)
- type Manager
- type Storage
- type StorageDisk
- type StorageMemory
- func (s *StorageMemory) Delete(ctx context.Context, id string) error
- func (s *StorageMemory) Load(ctx context.Context, id string) ([]byte, error)
- func (s *StorageMemory) Prune(ctx context.Context, maxAge time.Duration) error
- func (s *StorageMemory) Save(ctx context.Context, id string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Manager ¶
type Manager struct {
// SessionCookieName is the mutable name used to read and write the session
// cookie. PHP may change it with `$session->SessionCookieName = "sid"`.
SessionCookieName string
// contains filtered or unexported fields
}
Manager associates an HTTP-only cookie with data in Storage. The cookie contains only an opaque, randomly generated session ID.
func NewManager ¶
NewManager creates a manager backed by storage.
type Storage ¶
type Storage interface {
Load(ctx context.Context, id string) ([]byte, error)
Save(ctx context.Context, id string, data []byte) error
Delete(ctx context.Context, id string) error
Prune(ctx context.Context, maxAge time.Duration) error
}
Storage persists opaque session data by ID.
type StorageDisk ¶
type StorageDisk struct {
// contains filtered or unexported fields
}
StorageDisk stores sessions in a local folder.
func NewStorageDisk ¶
func NewStorageDisk(storagePaths ...string) (*StorageDisk, error)
NewStorageDisk creates the storage folder and verifies that it is writable. With no path, it uses the operating system's temporary directory.
func (*StorageDisk) Delete ¶
func (s *StorageDisk) Delete(ctx context.Context, id string) error
Delete removes a session from disk.
type StorageMemory ¶
type StorageMemory struct {
// contains filtered or unexported fields
}
StorageMemory stores sessions in memory. Its contents are not durable.
func NewStorageMemory ¶
func NewStorageMemory() *StorageMemory
NewStorageMemory creates empty in-memory session storage.
func (*StorageMemory) Delete ¶
func (s *StorageMemory) Delete(ctx context.Context, id string) error
Delete removes a session from memory.