session

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package session provides session management using Fiber's session middleware.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Expiration is the session expiration time.
	Expiration time.Duration

	// CookieName is the name of the session cookie.
	CookieName string

	// CookiePath is the path of the session cookie.
	CookiePath string

	// CookieDomain is the domain of the session cookie.
	CookieDomain string

	// CookieSecure indicates if the cookie should only be sent over HTTPS.
	CookieSecure bool

	// CookieHTTPOnly indicates if the cookie should be HTTP only.
	CookieHTTPOnly bool

	// CookieSameSite controls the SameSite attribute.
	CookieSameSite string

	// KeyLookup is the key lookup format (e.g., "cookie:session_id").
	KeyLookup string

	// Storage is the storage driver name.
	Storage string
}

Config holds session configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default session configuration.

type Driver

type Driver interface {
	// Get retrieves session data.
	Get(id string) (map[string]any, error)

	// Set stores session data.
	Set(id string, data map[string]any, expiration time.Duration) error

	// Delete removes session data.
	Delete(id string) error

	// Clear removes all sessions.
	Clear() error
}

Driver is the interface for session storage drivers.

type Manager

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

Manager manages sessions.

func NewManager

func NewManager(config ...Config) *Manager

NewManager creates a new session manager.

func (*Manager) Get

func (m *Manager) Get(c *fiber.Ctx) (*Session, error)

Get retrieves or creates a session for the given Fiber context.

func (*Manager) Middleware

func (m *Manager) Middleware() fiber.Handler

Middleware returns Fiber middleware for session handling.

func (*Manager) Store

func (m *Manager) Store() *session.Store

Store returns the underlying Fiber session store.

type Session

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

Session wraps Fiber's session with Laravel-like API.

func GetFromContext

func GetFromContext(c *fiber.Ctx) *Session

GetFromContext retrieves the session from Fiber context.

func (*Session) All

func (s *Session) All() map[string]any

All returns all session data.

func (*Session) CreatedAt

func (s *Session) CreatedAt() time.Time

CreatedAt returns when the session was created.

func (*Session) Destroy

func (s *Session) Destroy() error

Destroy destroys the session.

func (*Session) Flash

func (s *Session) Flash(key string, value any) error

Flash stores a value for the next request only.

func (*Session) Flush

func (s *Session) Flush() error

Flush removes all values from the session.

func (*Session) Forget

func (s *Session) Forget(key string) error

Forget removes a value from the session.

func (*Session) Get

func (s *Session) Get(key string) any

Get retrieves a value from the session.

func (*Session) GetBool

func (s *Session) GetBool(key string) bool

GetBool retrieves a boolean value from the session.

func (*Session) GetInt

func (s *Session) GetInt(key string) int

GetInt retrieves an integer value from the session.

func (*Session) GetString

func (s *Session) GetString(key string) string

GetString retrieves a string value from the session.

func (*Session) Has

func (s *Session) Has(key string) bool

Has checks if a key exists in the session.

func (*Session) ID

func (s *Session) ID() string

ID returns the session ID.

func (*Session) Keep

func (s *Session) Keep(keys ...string) error

Keep keeps specific flash data for another request.

func (*Session) LastActivity

func (s *Session) LastActivity() time.Time

LastActivity returns the last activity time.

func (*Session) Pull

func (s *Session) Pull(key string) any

Pull retrieves and removes a value from the session.

func (*Session) Reflash

func (s *Session) Reflash() error

Reflash keeps all flash data for another request.

func (*Session) Regenerate

func (s *Session) Regenerate() error

Regenerate regenerates the session ID.

func (*Session) Save

func (s *Session) Save() error

Save saves the session.

func (*Session) Set

func (s *Session) Set(key string, value any) error

Set stores a value in the session.

Jump to

Keyboard shortcuts

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