session

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	//Load a Session by sessionID
	Load(sessionID string) (session Session, found bool, err error)
	//Save a Session with given sessionID
	Save(sessionID string, session Session) (ttl int, err error)
}

Handler session Handler

type Memory

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

Memory memor Session implement for test perpose

func (*Memory) Load

func (s *Memory) Load(sessionID string) (Session, bool, error)

Load Session handle implement

func (*Memory) Save

func (s *Memory) Save(sessionID string, session Session) (ttl int, err error)

Save Session handle implement

type Redis

type Redis struct {
	TTL int
	// contains filtered or unexported fields
}

Redis redis session handler

func NewRedisHandler

func NewRedisHandler(store *redis.Client, ttl int, generater StorableSessionGenerater) *Redis

NewRedisHandler NewRedisHandler

func NewXinRedisHandler

func NewXinRedisHandler(store *redis.Client, ttl int) *Redis

NewXinRedisHandler return a redis handler use xinSession as generater

func (*Redis) Load

func (s *Redis) Load(sessionID string) (Session, bool, error)

Load implement Handler

func (*Redis) Save

func (s *Redis) Save(sessionID string, session Session) (ttl int, err error)

Save implement Handler

type Session

type Session interface {
	// Get session content by key
	Get(key string) (value interface{}, exists bool)
	// Set session content by key
	Set(key string, value interface{}) error
	// Delete session content by key
	Delete(key string) error
	// SetTTL set session ttl second
	SetTTL(ttl int) error
	// GetTTL get session ttl second
	GetTTL() int
}

Session session interface

type StorableSession

type StorableSession interface {
	Session
	// whether Session struct has new content after last generate
	HasNewContent() bool
	// marshal session into byte
	Marshal() (result []byte, err error)
	// unmarshal session from byte
	Unmarshal(raw []byte) (err error)
}

StorableSession storable session interface

type StorableSessionGenerater

type StorableSessionGenerater func() StorableSession

StorableSessionGenerater StorableSessionGenerater

type XinSession

type XinSession struct {
	Values map[string]interface{}
	// contains filtered or unexported fields
}

XinSession a simple implementation of Session interface

func NewXinSession

func NewXinSession() *XinSession

NewXinSession create a new xin session

func (*XinSession) Delete

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

Delete implement Session

func (*XinSession) Get

func (s *XinSession) Get(key string) (interface{}, bool)

Get implement Session

func (*XinSession) GetTTL

func (s *XinSession) GetTTL() int

GetTTL implement Session

func (*XinSession) HasNewContent

func (s *XinSession) HasNewContent() bool

HasNewContent implement StorableSession

func (*XinSession) Marshal

func (s *XinSession) Marshal() (result []byte, err error)

Marshal implement StorableSession

func (*XinSession) Set

func (s *XinSession) Set(key string, value interface{}) error

Set implement Session

func (*XinSession) SetTTL

func (s *XinSession) SetTTL(ttl int) error

SetTTL implement Session

func (*XinSession) Unmarshal

func (s *XinSession) Unmarshal(raw []byte) (err error)

Unmarshal implement StorableSession

Jump to

Keyboard shortcuts

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