package module
Version: v0.0.0-...-a7a7c39 Latest Latest

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

Go to latest
Published: May 13, 2016 License: MIT Imports: 9 Imported by: 3


Orivil session component


go get -v


cd $GOPATH/src/

go test example_test.go


see example_test.go



Released under the MIT License.



Package session provide a full-featured session component.



This section is empty.


This section is empty.


func ConfigMemory

func ConfigMemory(maxAgeMinute, checkNum int, cookieKey string)

func ConfigPermanent

func ConfigPermanent(maxAgeMinute, checkNum int, cookieKey string)

func Log

func Log()

func SetStorage

func SetStorage(s Storage)

func StorePermanentSession

func StorePermanentSession(s *Session)


type DBSession

type DBSession struct {
	ID     int    `gorm:"primary_key"`
	SID    string `gorm:"type:char(36);index;not null;"`
	Values string `gorm:"type:varchar(255);not null"`

type DBStorage

type DBStorage struct {
	// contains filtered or unexported fields

func NewDBStorage

func NewDBStorage(driver string, db *sql.DB) *DBStorage

func (*DBStorage) Destroy

func (this *DBStorage) Destroy(ids []string) (destroyed []string)

func (*DBStorage) GetAll

func (this *DBStorage) GetAll() (ids []string)

func (*DBStorage) Read

func (this *DBStorage) Read(id string) *Session

func (*DBStorage) Write

func (this *DBStorage) Write(s *Session)

type IdDecoder

type IdDecoder struct {
	// contains filtered or unexported fields

IdDecoder for generate UUID or read from cookie

func NewIdDecoder

func NewIdDecoder(cookieKey string, maxAgeMinute int) *IdDecoder

func (*IdDecoder) New

func (idc *IdDecoder) New(w http.ResponseWriter) (id string)

func (*IdDecoder) Read

func (idc *IdDecoder) Read(w http.ResponseWriter, r *http.Request) (id string)

Read for read id from cookie or generate a new id and it will auto update cookie

type Session

type Session struct {
	Id     string
	Values map[string]string
	// contains filtered or unexported fields

func New

func New(id string) *Session

func NewMemorySession

func NewMemorySession(w http.ResponseWriter, r *http.Request) *Session

func NewPermanentSession

func NewPermanentSession(w http.ResponseWriter, r *http.Request) *Session

func (*Session) Del

func (s *Session) Del(key string)

func (*Session) DelData

func (s *Session) DelData(key string)

func (*Session) Flash

func (s *Session) Flash(key string) (value string)

func (*Session) FlashData

func (s *Session) FlashData(key string) (data interface{})

func (*Session) Get

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

func (*Session) GetData

func (s *Session) GetData(key string) interface{}

func (*Session) ID

func (s *Session) ID() string

func (*Session) Set

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

func (*Session) SetData

func (s *Session) SetData(key string, data interface{})

type SessionGC

type SessionGC struct {
	// contains filtered or unexported fields
var MemoryGC *SessionGC
var PermanentGC *SessionGC

func NewSessionGC

func NewSessionGC() *SessionGC

func (*SessionGC) Config

func (gc *SessionGC) Config(maxAgeMinute int, cookieKey string, checkNum int)

func (*SessionGC) Destroy

func (gc *SessionGC) Destroy(now time.Time)

func (*SessionGC) GetID

func (gc *SessionGC) GetID(w http.ResponseWriter, r *http.Request) string

func (*SessionGC) Read

func (gc *SessionGC) Read(sessionID string) (s *Session)

func (*SessionGC) SetStorage

func (gc *SessionGC) SetStorage(s Storage)

type Storage

type Storage interface {

	// Destroy for deleting sessions and return destroyed ids
	Destroy(ids []string) (destroyed []string)

	// Read for reading the Session instance
	Read(id string) *Session

	// Write for updating session
	Write(s *Session)

	// GetAll for initializing GC time, it must return all of the stored ids
	GetAll() (ids []string)

Storage for storing and recovering the session value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL