session

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SessionExpiryHours is the number of hours before a session expires
	SessionExpiryHours = 24
	// SessionIDLength is the length of the session ID in bytes
	SessionIDLength = 32
	// SessionKey is a key used in the context
	SessionKey = "session"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStorage

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

FileStorage implements SessionStorage using file system

func NewFileStorage

func NewFileStorage(storeFile string, logger logging.Logger) *FileStorage

NewFileStorage creates a new file-based session storage

func (*FileStorage) Delete

func (fs *FileStorage) Delete(sessionID string) error

Delete implements SessionStorage.Delete

func (*FileStorage) Load

func (fs *FileStorage) Load() (map[string]*Session, error)

Load implements SessionStorage.Load

func (*FileStorage) Save

func (fs *FileStorage) Save(sessions map[string]*Session) error

Save implements SessionStorage.Save

type Manager

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

Manager manages user sessions

func NewManager

func NewManager(
	logger logging.Logger,
	cfg *SessionConfig,
	lc fx.Lifecycle,
	accessManager *access.AccessManager,
) *Manager

NewManager creates a new session manager

func (*Manager) ClearSessionCookie

func (sm *Manager) ClearSessionCookie(c echo.Context)

ClearSessionCookie clears the session cookie

func (*Manager) CreateSession

func (sm *Manager) CreateSession(userID, email, role string) (string, error)

CreateSession creates a new session for a user

func (*Manager) DeleteSession

func (sm *Manager) DeleteSession(sessionID string)

DeleteSession removes a session

func (*Manager) GetCookieName

func (sm *Manager) GetCookieName() string

GetCookieName returns the name of the session cookie

func (*Manager) GetSession

func (sm *Manager) GetSession(sessionID string) (*Session, bool)

GetSession retrieves a session by ID

func (*Manager) Middleware

func (sm *Manager) Middleware() echo.MiddlewareFunc

Middleware creates a new session middleware

func (*Manager) SessionMiddleware added in v0.2.0

func (sm *Manager) SessionMiddleware() echo.MiddlewareFunc

SessionMiddleware creates a new session middleware

func (*Manager) SetSessionCookie

func (sm *Manager) SetSessionCookie(c echo.Context, sessionID string)

SetSessionCookie sets the session cookie

type Session

type Session struct {
	UserID    string    `json:"user_id"`
	Email     string    `json:"email"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

Session represents a user session

type SessionConfig added in v0.2.0

type SessionConfig struct {
	*config.SessionConfig
	*config.Config
	PublicPaths  []string `json:"public_paths"`
	ExemptPaths  []string `json:"exempt_paths"`
	StaticPaths  []string `json:"static_paths"`
	ErrorHandler func(c echo.Context, message string) error
}

SessionConfig extends the base config with additional session-specific settings

type SessionStorage added in v0.2.0

type SessionStorage interface {
	Load() (map[string]*Session, error)
	Save(sessions map[string]*Session) error
	Delete(sessionID string) error
}

SessionStorage defines the interface for session storage operations

Jump to

Keyboard shortcuts

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