session

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package session provides an interface for managing user sessions. This file contains an implementation of the Store interface using an in-memory store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNewSessionID

func CreateNewSessionID(s Store) (string, error)

CreateNewSessionID generates a random session id. Also check for collisions so we don't accidentally assign an existing session id.

func TestStoreImplementation

func TestStoreImplementation(t *testing.T, impl StoreImplementation)

TestStoreImplementation tests a session store implementation.

Types

type Data

type Data map[string]interface{}

Data is the stored session data.

func (*Data) Scan

func (p *Data) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (*Data) Value

func (p *Data) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Session

type Session struct {
	ID      string
	Expires int64
	Data    Data
}

Session is the stored session data.

type Store

type Store interface {
	// CreateSession creates a new session in the store. The expires parameter is the expire
	// time in nanonseconds for the session. Returns the session ID.
	CreateSession(expires int64) (string, error)

	// GetSession returns the session from the session store based
	// on given ID and where expire is higher than provided nanoseconds.
	GetSession(sessionID string, ingnoreOlderNs int64) (Session, error)

	// RemoveSession removes the session from the store.
	RemoveSession(sessionID string) error

	// GetSessions returns sessions with expire time is less than given time in nanoseconds.
	GetSessions(time int64) ([]Session, error)

	// RefreshSession refreshes a session expire time by adding the given nanoseconds.
	RefreshSession(sessionID string, expireAddNs int64) error

	// SetSessionData sets the session data in the store.
	SetSessionData(sessionID string, data Data) error

	// GetSessionData returns the session data from the store.
	GetSessionData(sessionID string) (Data, error)

	// RemoveSessionData removes the session data from the store.
	RemoveSessionData(sessionID string) error
}

Store is the interface for the session back-end store.

func NewInMemoryStore

func NewInMemoryStore() Store

NewInMemoryStore returns a new instance of inMemoryStore.

type StoreImplementation

type StoreImplementation struct {
	Name      string
	StoreFunc func() Store
}

Jump to

Keyboard shortcuts

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