session

package
v0.2.13 Latest Latest
Warning

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

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

Documentation

Overview

Package session provides session management for persisting cookies and variables across HTTP requests, supporting both directory-scoped and named session modes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearAllSessions

func ClearAllSessions(baseDir string) error

ClearAllSessions removes all session data

func ClearAllSessionsWithFS added in v0.2.10

func ClearAllSessionsWithFS(fs filesystem.FileSystem, baseDir string) error

ClearAllSessionsWithFS removes all session data using a custom file system.

func ListAllSessions

func ListAllSessions(baseDir string) ([]string, error)

ListAllSessions returns all session directories

func ListAllSessionsWithFS added in v0.2.10

func ListAllSessionsWithFS(fs filesystem.FileSystem, baseDir string) ([]string, error)

ListAllSessionsWithFS returns all session directories using a custom file system.

Types

type Cookie struct {
	Name     string    `json:"name"`
	Value    string    `json:"value"`
	Path     string    `json:"path,omitempty"`
	Domain   string    `json:"domain,omitempty"`
	Expires  time.Time `json:"expires,omitempty"`
	MaxAge   int       `json:"maxAge,omitempty"`
	Secure   bool      `json:"secure,omitempty"`
	HttpOnly bool      `json:"httpOnly,omitempty"`
	SameSite string    `json:"sameSite,omitempty"`
}

Cookie represents a serializable cookie

type SessionManager

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

SessionManager manages session persistence (cookies and variables)

func NewSessionManager

func NewSessionManager(baseDir, httpFilePath, sessionName string) (*SessionManager, error)

NewSessionManager creates a new session manager If sessionName is provided, uses named session; otherwise uses directory-based session

func NewSessionManagerWithFS added in v0.2.10

func NewSessionManagerWithFS(fs filesystem.FileSystem, baseDir, httpFilePath, sessionName string) (*SessionManager, error)

NewSessionManagerWithFS creates a new session manager with a custom file system. This is primarily useful for testing.

func (*SessionManager) ClearAll

func (s *SessionManager) ClearAll()

ClearAll clears both cookies and variables

func (*SessionManager) ClearCookies

func (s *SessionManager) ClearCookies()

ClearCookies clears all cookies

func (*SessionManager) ClearVariables

func (s *SessionManager) ClearVariables()

ClearVariables clears all variables

func (*SessionManager) Delete

func (s *SessionManager) Delete() error

Delete removes the session directory from disk

func (*SessionManager) GetAllCookies

func (s *SessionManager) GetAllCookies() map[string][]Cookie

GetAllCookies returns all cookies

func (*SessionManager) GetAllVariables

func (s *SessionManager) GetAllVariables() map[string]any

GetAllVariables returns all session variables

func (*SessionManager) GetCookiesForURL

func (s *SessionManager) GetCookiesForURL(urlStr string) []*http.Cookie

GetCookiesForURL returns cookies for a given URL

func (*SessionManager) GetSessionPath

func (s *SessionManager) GetSessionPath() string

GetSessionPath returns the session path (for display purposes)

func (*SessionManager) GetVariable

func (s *SessionManager) GetVariable(name string) (any, bool)

GetVariable gets a session variable

func (*SessionManager) GetVariableAsString

func (s *SessionManager) GetVariableAsString(name string) (string, bool)

GetVariableAsString gets a session variable as string

func (*SessionManager) Load

func (s *SessionManager) Load() error

Load loads both cookies and variables from disk

func (*SessionManager) LoadCookies

func (s *SessionManager) LoadCookies() error

LoadCookies loads cookies from disk

func (*SessionManager) LoadVariables

func (s *SessionManager) LoadVariables() error

LoadVariables loads variables from disk

func (*SessionManager) Save

func (s *SessionManager) Save() error

Save saves both cookies and variables to disk

func (*SessionManager) SaveCookies

func (s *SessionManager) SaveCookies() error

SaveCookies saves cookies to disk

func (*SessionManager) SaveVariables

func (s *SessionManager) SaveVariables() error

SaveVariables saves variables to disk

func (*SessionManager) SetCookiesFromResponse

func (s *SessionManager) SetCookiesFromResponse(urlStr string, cookies []*http.Cookie)

SetCookiesFromResponse stores cookies from an HTTP response

func (*SessionManager) SetVariable

func (s *SessionManager) SetVariable(name string, value any)

SetVariable sets a session variable

Jump to

Keyboard shortcuts

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