type Manager struct {
provider Provider
config *ManagerConfig
}
// getSid retrieves session identifier from HTTP Request.
// First try to retrieve id by reading from cookie, session cookie name is configurable,
// if not exist, then retrieve id from querying parameters.
//
// error is not nil when there is anything wrong.
// sid is empty when need to generate a new session id
// otherwise return an valid session id.
func (manager *Manager) getSid(r *http.Request) (string, error)
// SessionStart generate or read the session id from http request.
// if session id exists, return SessionStore with this id.
func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (session Store, err error)
// SessionDestroy Destroy session by its id in http request cookie
func (manager *Manager) SessionDestroy(w http.ResponseWriter, r *http.Request)
// GetSessionStore Get SessionStore by its id
func (manager *Manager) GetSessionStore(sid string) (sessions Store, err error)
// GC Start session gc process.
// it can do gc in times after gc lifetime.
func (manager *Manager) GC()
// SessionRegenerateID Regenerate a session id for this SessionStore who's id is saving in http request.
func (manager *Manager) SessionRegenerateID(w http.ResponseWriter, r *http.Request) (session Store)
// GetActiveSession Get all active sessions count number.
func (manager *Manager) GetActiveSession() int
// Set cookie with https
func (manager *Manager) SetSecure(req *http.Request) bool
// inner function
func (manager *Manager) sessionID() (string, error)
// inner function
func (manager *Manager) isSecure(req *http.Request) bool
Store interface
// Store contains all data for one session process with specific id.
type Store 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
}
MemSessionStore struct
type MemSessionStore struct {
sid string //session id
timeAccessed time.Time //last access time
value map[interface{}]interface{} //session store
lock sync.RWMutex
}
// Set value to memory session
func (st *MemSessionStore) Set(key, value interface{}) error
// Get value from memory session by key
func (st *MemSessionStore) Get(key interface{}) interface{}
// Delete in memory session by key
func (st *MemSessionStore) Delete(key interface{}) error
// Flush clear all values in memory session
func (st *MemSessionStore) Flush() error
// SessionID get this id of memory session store
func (st *MemSessionStore) SessionID() string
// SessionRelease Implement method, no used.
func (st *MemSessionStore) SessionRelease(w http.ResponseWriter)