session

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SameSiteLaxMode    = "lax"
	SameSiteStrictMode = "strict"
	SameSiteNoneMode   = "none"
)
View Source
const DefaultSessionName string = "GFRRSESSID"

Variables

View Source
var (
	ErrNotInitialized     = errors.New("session manager not initialized")
	ErrNilConfig          = errors.New("session config cannot be nil")
	ErrInvalidStore       = errors.New("invalid session store type")
	ErrInvalidEncoding    = errors.New("invalid session encoding")
	ErrInvalidCookie      = errors.New("invalid cookie configuration")
	ErrNoSessionInContext = errors.New("no session data in context")
)

Functions

func Bool

func Bool(v bool) *bool

Bool returns a pointer to the provided bool value.

func ParseSameSite

func ParseSameSite(value string) http.SameSite

Types

type Config

type Config struct {
	Store            StoreConfig
	Cookie           CookieConfig
	Lifetime         time.Duration
	IdleTimeout      time.Duration
	HashTokenInStore *bool
	Encoding         Encoding
	ErrorHandler     ErrorHandler
}

Config controls session initialization.

type CookieConfig

type CookieConfig struct {
	Name        string
	Domain      string
	Path        string
	SameSite    http.SameSite
	Secure      *bool
	HttpOnly    *bool
	Persist     *bool
	Partitioned *bool
}

CookieConfig controls the session cookie settings.

type Encoding

type Encoding string

Encoding defines the session encoding format.

const (
	EncodingGob  Encoding = "gob"
	EncodingJSON Encoding = "json"
)

func ParseSessionEncoding

func ParseSessionEncoding(value string) Encoding

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, *http.Request, error)

ErrorHandler is invoked when the session middleware encounters an error.

type Manager

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

Manager provides a vendor-neutral session API over SCS.

func New

func New(config *Config) (*Manager, error)

New creates a new session manager with the provided configuration.

func (*Manager) Clear

func (m *Manager) Clear(ctx context.Context) error

Clear removes all session values.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the underlying store if supported.

func (*Manager) Deadline

func (m *Manager) Deadline(ctx context.Context) (time.Time, error)

Deadline returns the absolute expiry time.

func (*Manager) Destroy

func (m *Manager) Destroy(ctx context.Context) error

Destroy clears the session and deletes it from the store.

func (*Manager) Exists

func (m *Manager) Exists(ctx context.Context, key string) (bool, error)

Exists reports whether a key exists.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, key string) (interface{}, bool, error)

Get fetches a value from the session.

func (*Manager) GetBool

func (m *Manager) GetBool(ctx context.Context, key string) (bool, error)

GetBool fetches a bool value from the session.

func (*Manager) GetInt

func (m *Manager) GetInt(ctx context.Context, key string) (int, error)

GetInt fetches an int value from the session.

func (*Manager) GetString

func (m *Manager) GetString(ctx context.Context, key string) (string, error)

GetString fetches a string value from the session.

func (*Manager) Load

func (m *Manager) Load(ctx context.Context, token string) (context.Context, error)

Load manually loads session data into the context for non-middleware usage.

func (*Manager) Middleware

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

Middleware returns a middleware using this manager.

func (*Manager) Pop

func (m *Manager) Pop(ctx context.Context, key string) (interface{}, bool, error)

Pop removes and returns a value from the session.

func (*Manager) Put

func (m *Manager) Put(ctx context.Context, key string, val interface{}) error

Put stores a value in the session.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, key string) error

Remove deletes a value from the session.

func (*Manager) Renew

func (m *Manager) Renew(ctx context.Context) error

Renew rotates the session token.

func (*Manager) Token

func (m *Manager) Token(ctx context.Context) (string, error)

Token returns the current session token.

type StoreConfig

type StoreConfig struct {
	Type    StoreType
	Options StoreOptions
}

StoreConfig controls the session store configuration.

type StoreOptions

type StoreOptions struct {
	Name       string
	Address    string
	Username   string
	Password   string
	DB         int
	KeyPrefix  string
	PoolSize   int
	PingOnInit *bool
}

StoreOptions holds store-specific configuration values.

type StoreType

type StoreType string

StoreType defines the backing store type.

const (
	StoreMemory StoreType = "memory"
	StoreRedis  StoreType = "redis"
)

Jump to

Keyboard shortcuts

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