file

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package file keeps sessions in files, in a directory, one for each, named by the SHA-256 of its token, which isn't kept, so they last when the server restarts, without a database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(*Sessions)

Opt is an option of the sessions

func WithClock

func WithClock(now func() time.Time) Opt

WithClock is the time, such as in tests

type Sessions

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

Sessions keeps sessions in files, in a directory, which only its owner can read

func New

func New(dir string, opts ...Opt) (*Sessions, error)

New returns sessions in the directory, which is made, when it isn't, and which only its owner can read or write, so no one else can read sessions, or add one, with a token they choose

func (*Sessions) Consume

func (s *Sessions) Consume(_ context.Context, id string, expires time.Time) error

Consume consumes the ID, until it expires, as a file, named by its hash, which is created only when it isn't there, so it's consumed once, by any server which shares the directory, or after a restart. Those which have expired are removed.

func (*Sessions) Create

func (s *Sessions) Create(_ context.Context, session schema.Session) (*schema.SessionToken, error)

Create keeps a new session, with a new token, whose hash is its ID and file name, and removes those which have expired

func (*Sessions) Key

func (s *Sessions) Key() ([]byte, error)

Key returns the key of the sessions, of 32 bytes, such as the one which seals sign-ins, and OAuth clients' IDs and codes, so they last when the server restarts, and servers which share the directory accept each other's. It's in the directory, which only its owner can read, out of reach of anything else, such as credentials, which could replace it. It's made when it isn't there, at once, so when servers make it at the same time, there's one, which they all return.

func (*Sessions) Revoke

func (s *Sessions) Revoke(_ context.Context, id string) error

Revoke removes the session with the ID, or returns not found

func (*Sessions) Session

func (s *Sessions) Session(_ context.Context, token string) (*schema.Session, error)

Session returns the session of the token, or not authorized, when there isn't one, or it's expired

Jump to

Keyboard shortcuts

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