session

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNilEncoder   = errors.New("encoder is nil")
	ErrorNilDecoder   = errors.New("decoder is nil")
	ErrorNilSessionID = errors.New("sessionID is nil")
	ErrorExpire       = errors.New("session is expire")
	ErrorNilSession   = errors.New("session is not found")
)

Functions

This section is empty.

Types

type Decoder

type Decoder interface {
	Decode(string) (interface{}, error)
}

type Encoder

type Encoder interface {
	Encode(interface{}) (string, error)
}

type Option

type Option struct {
	Expire time.Duration
	// Encoder - encode input value and persistent
	Encoder Encoder
	// Decodeer - decode persistented data
	Decoder Decoder
}

type OptionFunc

type OptionFunc func(*Option)

func WithExpire

func WithExpire(expire time.Duration) OptionFunc

type SQLiteSessionManager

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

func (*SQLiteSessionManager) Load

func (s *SQLiteSessionManager) Load(sessionID string, opts ...OptionFunc) (Session, error)

func (*SQLiteSessionManager) New

func (s *SQLiteSessionManager) New(sessionID string, opts ...OptionFunc) (Session, error)

type Session

type Session interface {
	// Set - store value of this session
	Set(value interface{}, opt Option) error

	// Get - get persistent value of this session set before
	Get() (value interface{}, err error)

	// Close - close the session
	Close() error
}

Session - maintain the session about a user or group

type SessionManager

type SessionManager interface {
	// New - create a new session
	// it will start a new session
	// if the session is created before, it will overwrite it
	New(sessionID string, opts ...OptionFunc) (Session, error)

	// Load - get the session
	// if the session is created before, it will load the existing session
	// else return error
	Load(sessionID string, opts ...OptionFunc) (Session, error)
}

func NewSQLLiteSessionManager

func NewSQLLiteSessionManager(dsn string) (SessionManager, error)

type SessionModel

type SessionModel struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`

	ID     string `json:"session_id" gorm:"column:session_id;primaryKey"`
	Value  string `json:"session_value" gorm:"column:session_value"`
	Expire int64  `json:"session_expire" gorm:"column:session_expire"`
}

func (*SessionModel) TableName

func (s *SessionModel) TableName() string

type SqliteSession

type SqliteSession struct {
	SessionID string
	// contains filtered or unexported fields
}

func (*SqliteSession) Close

func (s *SqliteSession) Close() error

func (*SqliteSession) Get

func (s *SqliteSession) Get() (interface{}, error)

func (*SqliteSession) Set

func (s *SqliteSession) Set(value interface{}, opt Option) (err error)

Jump to

Keyboard shortcuts

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