session

package
v0.0.0-...-9184677 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2014 License: MIT Imports: 21 Imported by: 3

README

session

session is a Go session manager for Flotilla, a reimplementation of beego/session.

It can use alternate session providers, like the database/sql and database/sql/driver packages.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeGob

func DecodeGob(encoded []byte) (map[interface{}]interface{}, error)

func EncodeGob

func EncodeGob(obj map[interface{}]interface{}) ([]byte, error)

func RandomCreateBytes

func RandomCreateBytes(n int, alphabets ...byte) []byte

RandomCreateBytes generate random []byte by specify chars.

func Register

func Register(name string, provide Provider)

Register makes a session provide available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

Types

type CookieProvider

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

func (*CookieProvider) SessionAll

func (pder *CookieProvider) SessionAll() int

Implement method, return 0.

func (*CookieProvider) SessionDestroy

func (pder *CookieProvider) SessionDestroy(sid string) error

Method not implemented.

func (*CookieProvider) SessionExist

func (pder *CookieProvider) SessionExist(sid string) bool

Cookie session is always existed

func (*CookieProvider) SessionGC

func (pder *CookieProvider) SessionGC()

Method not implemented.

func (*CookieProvider) SessionInit

func (pder *CookieProvider) SessionInit(maxlifetime int64, config string) error

Init cookie session provider with max lifetime and config json. maxlifetime is ignored. json config:

securityKey - hash string
blockKey - gob encode hash string. it's saved as aes crypto.
securityName - recognized name in encoded cookie string
cookieName - cookie name
maxage - cookie max life time.

func (*CookieProvider) SessionRead

func (pder *CookieProvider) SessionRead(sid string) (SessionStore, error)

Get SessionStore in cooke. decode cookie string to map and put into SessionStore with sid.

func (*CookieProvider) SessionRegenerate

func (pder *CookieProvider) SessionRegenerate(oldsid, sid string) (SessionStore, error)

Method not implemented.

func (*CookieProvider) SessionUpdate

func (pder *CookieProvider) SessionUpdate(sid string) error

Method not implemented.

type CookieSessionStore

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

func (*CookieSessionStore) Delete

func (st *CookieSessionStore) Delete(key interface{}) error

Delete value in cookie session

func (*CookieSessionStore) Flush

func (st *CookieSessionStore) Flush() error

Clean all values in cookie session

func (*CookieSessionStore) Get

func (st *CookieSessionStore) Get(key interface{}) interface{}

Get value from cookie session

func (*CookieSessionStore) SessionID

func (st *CookieSessionStore) SessionID() string

Return id of this cookie session

func (*CookieSessionStore) SessionRelease

func (st *CookieSessionStore) SessionRelease(w http.ResponseWriter)

Write cookie session to http response cookie

func (*CookieSessionStore) Set

func (st *CookieSessionStore) Set(key, value interface{}) error

Set value to cookie session. the value are encoded as gob with hash block string.

type Manager

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

Manager contains Provider and its configuration.

func NewManager

func NewManager(provideName, config string) (*Manager, error)

Create new Manager with provider name and json config string where provider is an existing valid provider(e.g. "cookie") and a json config.

func (*Manager) GC

func (manager *Manager) GC()

Start session gc process. it can do gc in times after gc lifetime.

func (*Manager) GetActiveSession

func (manager *Manager) GetActiveSession() int

Get all active sessions count number.

func (*Manager) GetSessionStore

func (manager *Manager) GetSessionStore(sid string) (sessions SessionStore, err error)

Get SessionStore by its id.

func (*Manager) SessionDestroy

func (manager *Manager) SessionDestroy(w http.ResponseWriter, r *http.Request)

Destroy session by its id in http request cookie.

func (*Manager) SessionRegenerateId

func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Request) (session SessionStore)

Regenerate a session id for this SessionStore who's id is saving in http request.

func (*Manager) SessionStart

func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (session SessionStore)

Start session. generate or read the session id from http request. if session id exists, return SessionStore with this id.

func (*Manager) SetHashFunc

func (manager *Manager) SetHashFunc(hasfunc, hashkey string)

Set hash function for generating session id.

func (*Manager) SetSecure

func (manager *Manager) SetSecure(secure bool)

Set cookie with https.

type Provider

type Provider interface {
	SessionInit(gclifetime int64, config string) error
	SessionRead(sid string) (SessionStore, error)
	SessionExist(sid string) bool
	SessionRegenerate(oldsid, sid string) (SessionStore, error)
	SessionDestroy(sid string) error
	SessionAll() int //get all active session
	SessionGC()
}

Provider contains global session methods and saved SessionStores. it can operate a SessionStore by its id.

type SessionStore

type SessionStore interface {
	Set(key, value interface{}) error     //set session value
	Get(key interface{}) interface{}      //get session value
	Delete(key interface{}) error         //delete session value
	SessionID() string                    //back current sessionID
	SessionRelease(w http.ResponseWriter) //release the resource & save data to provider & return the data
	Flush() error                         //delete all data
}

SessionStore contains all data for one session process with specific id.

Jump to

Keyboard shortcuts

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