Documentation
¶
Index ¶
- Variables
- func DestroySession(c *goexpress.Context, config Config) error
- func Flash(c *goexpress.Context, key string, value interface{}) error
- func GetFlash(c *goexpress.Context, key string) (interface{}, bool)
- func Middleware(config Config) goexpress.Middleware
- func RegenerateSession(c *goexpress.Context, config Config) error
- type Config
- type CookieStore
- func (c *CookieStore) Cleanup() error
- func (c *CookieStore) Delete(id string) error
- func (c *CookieStore) Encode(session *Session) (string, error)
- func (c *CookieStore) Get(cookieValue string) (*Session, error)
- func (c *CookieStore) Set(session *Session) error
- func (c *CookieStore) Touch(id string) error
- type MemoryStore
- type RedisConfig
- type RedisStore
- func (r *RedisStore) Cleanup() error
- func (r *RedisStore) Clear() error
- func (r *RedisStore) Close() error
- func (r *RedisStore) Count() (int64, error)
- func (r *RedisStore) Delete(id string) error
- func (r *RedisStore) Exists(id string) (bool, error)
- func (r *RedisStore) Get(id string) (*Session, error)
- func (r *RedisStore) GetClient() *redis.Client
- func (r *RedisStore) Set(session *Session) error
- func (r *RedisStore) SetWithTTL(session *Session, ttl time.Duration) error
- func (r *RedisStore) Touch(id string) error
- type Session
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSessionNotFound is returned when a session is not found ErrSessionNotFound = errors.New("session not found") // ErrSessionExpired is returned when a session has expired ErrSessionExpired = errors.New("session expired") )
Functions ¶
func DestroySession ¶
DestroySession removes the session
func Middleware ¶
func Middleware(config Config) goexpress.Middleware
Middleware returns a session middleware for GoExpress
Types ¶
type Config ¶
type Config struct {
Store Store
CookieName string
CookiePath string
CookieDomain string
MaxAge time.Duration
Secure bool
HttpOnly bool
SameSite http.SameSite
ContextKey string
}
Config holds session middleware configuration
func DefaultConfig ¶
DefaultConfig returns a default session configuration
type CookieStore ¶
type CookieStore struct {
// contains filtered or unexported fields
}
CookieStore implements cookie-based session storage
func NewCookieStore ¶
func NewCookieStore(maxAge time.Duration) *CookieStore
NewCookieStore creates a new cookie store
func (*CookieStore) Cleanup ¶
func (c *CookieStore) Cleanup() error
Cleanup is a no-op for cookie store
func (*CookieStore) Delete ¶
func (c *CookieStore) Delete(id string) error
Delete is a no-op for cookie store
func (*CookieStore) Encode ¶
func (c *CookieStore) Encode(session *Session) (string, error)
Encode encodes a session to cookie format
func (*CookieStore) Get ¶
func (c *CookieStore) Get(cookieValue string) (*Session, error)
Get decodes a session from cookie data
func (*CookieStore) Set ¶
func (c *CookieStore) Set(session *Session) error
Set encodes a session to cookie format
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore implements an in-memory session store
func NewMemoryStore ¶
func NewMemoryStore(cleanupInterval time.Duration) *MemoryStore
NewMemoryStore creates a new in-memory session store
func (*MemoryStore) Cleanup ¶
func (m *MemoryStore) Cleanup() error
Cleanup removes expired sessions
func (*MemoryStore) Get ¶
func (m *MemoryStore) Get(id string) (*Session, error)
Get retrieves a session
func (*MemoryStore) Touch ¶
func (m *MemoryStore) Touch(id string) error
Touch updates the last access time
type RedisConfig ¶
type RedisConfig struct {
Addr string // Redis server address (e.g., "localhost:6379")
Password string // Password for authentication
DB int // Database number
Prefix string // Key prefix for sessions (e.g., "session:")
}
RedisConfig holds Redis connection configuration
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore implements a Redis-based session store
func NewRedisStore ¶
func NewRedisStore(config RedisConfig) (*RedisStore, error)
NewRedisStore creates a new Redis session store
func (*RedisStore) Cleanup ¶
func (r *RedisStore) Cleanup() error
Cleanup is a no-op for Redis (it handles expiration automatically)
func (*RedisStore) Count ¶
func (r *RedisStore) Count() (int64, error)
Count returns the number of active sessions
func (*RedisStore) Delete ¶
func (r *RedisStore) Delete(id string) error
Delete removes a session from Redis
func (*RedisStore) Exists ¶
func (r *RedisStore) Exists(id string) (bool, error)
Exists checks if a session exists
func (*RedisStore) Get ¶
func (r *RedisStore) Get(id string) (*Session, error)
Get retrieves a session from Redis
func (*RedisStore) GetClient ¶
func (r *RedisStore) GetClient() *redis.Client
GetClient returns the underlying Redis client for advanced operations
func (*RedisStore) Set ¶
func (r *RedisStore) Set(session *Session) error
Set stores a session in Redis
func (*RedisStore) SetWithTTL ¶
func (r *RedisStore) SetWithTTL(session *Session, ttl time.Duration) error
SetWithTTL stores a session with a custom TTL
func (*RedisStore) Touch ¶
func (r *RedisStore) Touch(id string) error
Touch updates the session's expiration time
type Session ¶
type Session struct {
ID string `json:"id"`
Data map[string]interface{} `json:"data"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Session represents a user session
func GetSession ¶
GetSession retrieves the session from the context
type Store ¶
type Store interface {
// Get retrieves a session by ID
Get(id string) (*Session, error)
// Set stores a session
Set(session *Session) error
// Delete removes a session
Delete(id string) error
// Cleanup removes expired sessions
Cleanup() error
// Touch updates the last access time
Touch(id string) error
}
Store is the interface for session storage backends