session

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// All package errors are wrapping Error
	Error          = errorFlag("session: error")
	ErrKeyExpired  = errorFlag("session: key expired")
	ErrKeyTampered = errorFlag("session: key tampered")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

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

Clock is a scaled monotonic clock. It increments time by 1 every step nanoseconds.

func (*Clock) Init

func (self *Clock) Init(step time.Duration) error

Init initializes the Clock. It errors if step <= 0

func (Clock) T

func (self Clock) T() int64

T returns the number of step since Init was called.

type KeyFactory

type KeyFactory[K comparable] interface {
	New(ad uint64) K
	Check(key K) error
}

type MemStore

type MemStore[K TimedKey, V any] struct {
	KeyFacto KeyFactory[K]
	// contains filtered or unexported fields
}

MemStore is an in memory session Store that automatically expires keys.

func NewMemStore

func NewMemStore[K TimedKey, V any](kf KeyFactory[K]) (*MemStore[K, V], error)

NewMemStore instantiates a new MemStore. It errors if kf is nil.

func (*MemStore[K, V]) Get

func (self *MemStore[K, V]) Get(key K) (V, bool)

Get returns the value indexed by key. The bool flag is true if the key exists in the MemStore.

func (*MemStore[K, V]) Pop

func (self *MemStore[K, V]) Pop(key K) (V, bool)

Pop removes the key from the MemStore and returns the associated value. The bool flag is true if the key was found in the MemStore.

func (*MemStore[K, V]) Save

func (self *MemStore[K, V]) Save(data V) (K, error)

Save registers data in the MemStore using a new key. Save returns the key indexing data.

func (*MemStore[K, V]) Set

func (self *MemStore[K, V]) Set(key K, data V) error

Set registers key, data in the MemStore. It errors if key is not valid.

type Sid

type Sid [sidSize]byte

Sid is a byte array used as session identifier. Sid bytes encode [mac|timestamp|counter|data]

func (Sid) AD added in v0.3.5

func (self Sid) AD() uint64

AD returns the Sid "additional data"

func (Sid) C

func (self Sid) C() uint64

C returns the Sid "counter".

func (Sid) T

func (self Sid) T() int64

T returns the Sid "timestamp".

type SidFactory

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

SidFactory generates unique Sids. It can check time validity and origin of Sid values.

func NewSidFactory

func NewSidFactory(lifetime time.Duration) (*SidFactory, error)

NewSidFactory instantiates a SidFactory. Generated Sid expires after lifetime. NewSidFactory errors if lifetime is invalid.

func (*SidFactory) Check

func (self *SidFactory) Check(sid Sid) error

Check errors if sid was not generated by the SidFactory or if sid has expired.

func (*SidFactory) New

func (self *SidFactory) New(ad uint64) Sid

New returns a new Sid different from Sid returned by previous calls.

type Store

type Store[K comparable, V any] interface {
	Get(key K) (V, bool)
	Pop(key K) (V, bool)
	Set(key K, data V) error
	Save(data V) (K, error)
}

type Timed

type Timed interface {
	// T returns a "pseudo time"
	T() int64
}

type TimedKey

type TimedKey interface {
	comparable
	Timed
}

Jump to

Keyboard shortcuts

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