basesession

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package basesession implements the session management for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseSession

type BaseSession struct {
	SessionTimeout time.Duration
	Handle         LogHandler
	Storage        sessionstorage.BaseStore
	cookie.CookieHandler
}

BaseSession implements the shared features for all session implementations

func (*BaseSession) Authenticated

func (s *BaseSession) Authenticated() http.HandlerFunc

Authenticated is the handler reports if the session is authenticated

func (*BaseSession) CheckSession added in v0.6.1

func (s *BaseSession) CheckSession(ctx context.Context) (context.Context, error)

CheckSession checks the session cookie and if it is valid, stores the session data into the context

func (*BaseSession) Logout

func (s *BaseSession) Logout() http.HandlerFunc

Logout is a handler which destroys the current session

func (*BaseSession) SetXSRFToken

func (s *BaseSession) SetXSRFToken(next http.Handler) http.Handler

SetXSRFToken sets the XSRF Token

func (*BaseSession) StartSession

func (s *BaseSession) StartSession(next http.Handler) http.Handler

StartSession initializes a session by restoring it from a cookie, or if that fails, initializing a new session. The session cookie is then updated and the sessionID is inserted into the context.

func (*BaseSession) ValidateSession

func (s *BaseSession) ValidateSession(next http.Handler) http.Handler

ValidateSession checks the sessionID in the database to validate that it has not expired and updates the last activity timestamp if it is still valid. StartSession handler must be called before calling ValidateSession

func (*BaseSession) ValidateXSRFToken

func (s *BaseSession) ValidateXSRFToken(next http.Handler) http.Handler

ValidateXSRFToken validates the XSRF Token

type Handlers

type Handlers interface {
	Authenticated() http.HandlerFunc
	Logout() http.HandlerFunc
	StartSession(next http.Handler) http.Handler
	ValidateSession(next http.Handler) http.Handler
	SetXSRFToken(next http.Handler) http.Handler
	ValidateXSRFToken(next http.Handler) http.Handler
}

Handlers defines the interface for session handlers used by all session implementations

type LogHandler

type LogHandler func(handler func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc

LogHandler defines the handler signature required for handling logs.

Jump to

Keyboard shortcuts

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