session

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	ID           string            `json:"id"`
	Headers      map[string]string `json:"headers"`
	CreatedAt    time.Time         `json:"created_at"`
	LastAccessed time.Time         `json:"last_accessed"`
	CallCount    int64             `json:"call_count"`
	UserAgent    string            `json:"user_agent"`
	RemoteAddr   string            `json:"remote_addr"`

	// Rate limiting
	RequestCount int64     `json:"request_count"`
	WindowStart  time.Time `json:"window_start"`

	// Security
	IsBlocked bool `json:"is_blocked"`
	// contains filtered or unexported fields
}

Context represents a session context

func (*Context) GetAge

func (ctx *Context) GetAge() time.Duration

GetAge returns the age of the session

func (*Context) GetCallCount

func (ctx *Context) GetCallCount() int64

GetCallCount returns the call count

func (*Context) GetHeader

func (ctx *Context) GetHeader(key string) string

GetHeader returns a header value

func (*Context) GetInfo

func (ctx *Context) GetInfo() map[string]interface{}

GetInfo returns session information

func (*Context) GetTimeSinceLastAccess

func (ctx *Context) GetTimeSinceLastAccess() time.Duration

GetTimeSinceLastAccess returns the time since last access

func (*Context) IncrementCallCount

func (ctx *Context) IncrementCallCount()

IncrementCallCount increments the call count

func (*Context) IsExpired

func (ctx *Context) IsExpired(expiration time.Duration) bool

IsExpired checks if the session is expired

func (*Context) SetHeader

func (ctx *Context) SetHeader(key, value string)

SetHeader sets a header value

func (*Context) UpdateLastAccessed

func (ctx *Context) UpdateLastAccessed()

UpdateLastAccessed updates the last accessed time

type Manager

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

Manager manages user sessions

func NewManager

func NewManager(logger *zap.Logger) *Manager

NewManager creates a new session manager

func (*Manager) BlockSession

func (m *Manager) BlockSession(sessionID string)

BlockSession blocks a session

func (*Manager) CheckRateLimit

func (m *Manager) CheckRateLimit(sessionID string) bool

CheckRateLimit checks if a session has exceeded the rate limit

func (*Manager) Close

func (m *Manager) Close() error

Close closes the session manager

func (*Manager) CreateSession

func (m *Manager) CreateSession(headers map[string]string) *Context

CreateSession creates a new session

func (*Manager) DeleteSession

func (m *Manager) DeleteSession(sessionID string)

DeleteSession removes a session

func (*Manager) GetActiveSessions

func (m *Manager) GetActiveSessions() []map[string]interface{}

GetActiveSessions returns information about active sessions

func (*Manager) GetOrCreateSession

func (m *Manager) GetOrCreateSession(sessionID string, headers map[string]string) *Context

GetOrCreateSession gets an existing session or creates a new one

func (*Manager) GetSession

func (m *Manager) GetSession(sessionID string) (*Context, bool)

GetSession retrieves a session by ID

func (*Manager) GetSessionStats

func (m *Manager) GetSessionStats() map[string]interface{}

GetSessionStats returns session statistics

func (*Manager) IsSessionBlocked

func (m *Manager) IsSessionBlocked(sessionID string) bool

IsSessionBlocked checks if a session is blocked

func (*Manager) UnblockSession

func (m *Manager) UnblockSession(sessionID string)

UnblockSession unblocks a session

func (*Manager) UpdateSession

func (m *Manager) UpdateSession(sessionID string, ctx *Context)

UpdateSession updates an existing session

Jump to

Keyboard shortcuts

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