session

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextEngValue  = "HTTPOKSESSCTXENGVALUE"
	ContextSessValue = "HTTPOKSESSCTXSESSVALUE"
	DefaultName      = "HTTPOKSESSID"
	DefaultPrefix    = "httpok:session"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder interface {
	Encode(any) ([]byte, error)
	Decode([]byte, any) error
}

type Engine

type Engine interface {
	Enabled() bool
	NewId() string
	SetEnabled(bool)
	// TODO: PurgeSession(id string)
	Name() string
	SetName(string)
	Read(string, any) error
	Start(context.Context) error
	Stop() error
	Store(string, any) error
	Purge() error
	GetSession(string, context.Context) (Session, error)
	SessionNotExists(string) (bool, error)
	StoreSession(string, Session) error
}

func EngineFromContext

func EngineFromContext(ctx context.Context) (Engine, error)

type EngineProperties

type EngineProperties struct {
	AgeLimit time.Duration

	Encoder
	logger.Logger

	// TODO: Add this to the interface
	Prefix        string
	PurgeDuration time.Duration
	// contains filtered or unexported fields
}

type FileEngine

type FileEngine struct {
	EngineProperties
	Dir string
}

func NewFileEngine

func NewFileEngine() *FileEngine

func (*FileEngine) Enabled

func (e *FileEngine) Enabled() bool

func (*FileEngine) GetSession

func (e *FileEngine) GetSession(id string, ctx context.Context) (Session, error)

func (*FileEngine) Name

func (e *FileEngine) Name() string

func (*FileEngine) NewId

func (e *FileEngine) NewId() string

func (*FileEngine) Purge

func (e *FileEngine) Purge() error

func (*FileEngine) Read

func (e *FileEngine) Read(id string, v any) error

func (*FileEngine) SessionNotExists

func (e *FileEngine) SessionNotExists(id string) (bool, error)

func (*FileEngine) SetEnabled

func (e *FileEngine) SetEnabled(enabled bool)

func (*FileEngine) SetName

func (e *FileEngine) SetName(n string)

func (*FileEngine) Start

func (e *FileEngine) Start(_ context.Context) error

func (*FileEngine) Stop

func (e *FileEngine) Stop() error

func (*FileEngine) Store

func (e *FileEngine) Store(id string, v any) error

func (*FileEngine) StoreSession

func (e *FileEngine) StoreSession(id string, s Session) error

type JsonEncoder

type JsonEncoder struct {
}

func (*JsonEncoder) Decode

func (e *JsonEncoder) Decode(data []byte, v any) error

func (*JsonEncoder) Encode

func (e *JsonEncoder) Encode(v any) ([]byte, error)

type RedisEngine

type RedisEngine struct {
	EngineProperties
	// contains filtered or unexported fields
}

func NewRedisEngine

func NewRedisEngine() (*RedisEngine, error)

func (*RedisEngine) Enabled

func (e *RedisEngine) Enabled() bool

func (*RedisEngine) GetSession

func (e *RedisEngine) GetSession(id string, ctx context.Context) (Session, error)

func (*RedisEngine) Name

func (e *RedisEngine) Name() string

func (*RedisEngine) NewId

func (e *RedisEngine) NewId() string

func (*RedisEngine) Purge

func (e *RedisEngine) Purge() error

func (*RedisEngine) Read

func (e *RedisEngine) Read(id string, v any) error

func (*RedisEngine) SessionNotExists

func (e *RedisEngine) SessionNotExists(id string) (bool, error)

func (*RedisEngine) SetEnabled

func (e *RedisEngine) SetEnabled(enabled bool)

func (*RedisEngine) SetName

func (e *RedisEngine) SetName(n string)

func (*RedisEngine) Start

func (e *RedisEngine) Start(ctx context.Context) error

func (*RedisEngine) Stop

func (e *RedisEngine) Stop() error

func (*RedisEngine) Store

func (e *RedisEngine) Store(id string, v any) error

func (*RedisEngine) StoreSession

func (e *RedisEngine) StoreSession(id string, s Session) error

type Session

type Session struct {
	Id        string
	Changed   bool
	Ctx       context.Context
	Data      map[string]any
	Destroyed bool
	Params    any
}

func SessionFromContext

func SessionFromContext(ctx context.Context) (*Session, error)

func (*Session) Clear

func (s *Session) Clear()

func (*Session) Delete

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

func (*Session) Destroy

func (s *Session) Destroy() error

func (*Session) Get

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

func (*Session) Has

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

func (*Session) Set

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

Jump to

Keyboard shortcuts

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