beego: github.com/astaxie/beego/adapter/session Index | Files | Directories

package session

import "github.com/astaxie/beego/adapter/session"

Package session provider

Usage: import(

"github.com/astaxie/beego/session"

)

	func init() {
     globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "cookieLifeTime": 3600, "providerConfig": ""}`)
		go globalSessions.GC()
	}

more docs: http://beego.me/docs/module/session.md

Index

Package Files

provider_adapter.go sess_cookie.go sess_file.go sess_mem.go sess_utils.go session.go store_adapter.go

Variables

var SLogger = NewSessionLog(os.Stderr)

SLogger a helpful variable to log information about session

func DecodeGob Uses

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

DecodeGob decode data to map

func EncodeGob Uses

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

EncodeGob encode the obj to gob

func Register Uses

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.

type CookieProvider Uses

type CookieProvider session.CookieProvider

CookieProvider Cookie session provider

func (*CookieProvider) SessionAll Uses

func (pder *CookieProvider) SessionAll() int

SessionAll Implement method, return 0.

func (*CookieProvider) SessionDestroy Uses

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

SessionDestroy Implement method, no used.

func (*CookieProvider) SessionExist Uses

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

SessionExist Cookie session is always existed

func (*CookieProvider) SessionGC Uses

func (pder *CookieProvider) SessionGC()

SessionGC Implement method, no used.

func (*CookieProvider) SessionInit Uses

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

SessionInit 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 Uses

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

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

func (*CookieProvider) SessionRegenerate Uses

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

SessionRegenerate Implement method, no used.

func (*CookieProvider) SessionUpdate Uses

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

SessionUpdate Implement method, no used.

type CookieSessionStore Uses

type CookieSessionStore session.CookieSessionStore

CookieSessionStore Cookie SessionStore

func (*CookieSessionStore) Delete Uses

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

Delete value in cookie session

func (*CookieSessionStore) Flush Uses

func (st *CookieSessionStore) Flush() error

Flush Clean all values in cookie session

func (*CookieSessionStore) Get Uses

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

Get value from cookie session

func (*CookieSessionStore) SessionID Uses

func (st *CookieSessionStore) SessionID() string

SessionID Return id of this cookie session

func (*CookieSessionStore) SessionRelease Uses

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

SessionRelease Write cookie session to http response cookie

func (*CookieSessionStore) Set Uses

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

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

type FileProvider Uses

type FileProvider session.FileProvider

FileProvider File session provider

func (*FileProvider) SessionAll Uses

func (fp *FileProvider) SessionAll() int

SessionAll Get active file session number. it walks save path to count files.

func (*FileProvider) SessionDestroy Uses

func (fp *FileProvider) SessionDestroy(sid string) error

SessionDestroy Remove all files in this save path

func (*FileProvider) SessionExist Uses

func (fp *FileProvider) SessionExist(sid string) bool

SessionExist Check file session exist. it checks the file named from sid exist or not.

func (*FileProvider) SessionGC Uses

func (fp *FileProvider) SessionGC()

SessionGC Recycle files in save path

func (*FileProvider) SessionInit Uses

func (fp *FileProvider) SessionInit(maxlifetime int64, savePath string) error

SessionInit Init file session provider. savePath sets the session files path.

func (*FileProvider) SessionRead Uses

func (fp *FileProvider) SessionRead(sid string) (Store, error)

SessionRead Read file session by sid. if file is not exist, create it. the file path is generated from sid string.

func (*FileProvider) SessionRegenerate Uses

func (fp *FileProvider) SessionRegenerate(oldsid, sid string) (Store, error)

SessionRegenerate Generate new sid for file session. it delete old file and create new file named from new sid.

type FileSessionStore Uses

type FileSessionStore session.FileSessionStore

FileSessionStore File session store

func (*FileSessionStore) Delete Uses

func (fs *FileSessionStore) Delete(key interface{}) error

Delete value in file session by given key

func (*FileSessionStore) Flush Uses

func (fs *FileSessionStore) Flush() error

Flush Clean all values in file session

func (*FileSessionStore) Get Uses

func (fs *FileSessionStore) Get(key interface{}) interface{}

Get value from file session

func (*FileSessionStore) SessionID Uses

func (fs *FileSessionStore) SessionID() string

SessionID Get file session store id

func (*FileSessionStore) SessionRelease Uses

func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter)

SessionRelease Write file session to local file with Gob string

func (*FileSessionStore) Set Uses

func (fs *FileSessionStore) Set(key, value interface{}) error

Set value to file session

type Log Uses

type Log session.Log

Log implement the log.Logger

func NewSessionLog Uses

func NewSessionLog(out io.Writer) *Log

NewSessionLog set io.Writer to create a Logger for session.

type Manager Uses

type Manager session.Manager

Manager contains Provider and its configuration.

func NewManager Uses

func NewManager(provideName string, cf *ManagerConfig) (*Manager, error)

NewManager Create new Manager with provider name and json config string. provider name: 1. cookie 2. file 3. memory 4. redis 5. mysql json config: 1. is https default false 2. hashfunc default sha1 3. hashkey default beegosessionkey 4. maxage default is none

func (*Manager) GC Uses

func (manager *Manager) GC()

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

func (*Manager) GetActiveSession Uses

func (manager *Manager) GetActiveSession() int

GetActiveSession Get all active sessions count number.

func (*Manager) GetProvider Uses

func (manager *Manager) GetProvider() Provider

GetProvider return current manager's provider

func (*Manager) GetSessionStore Uses

func (manager *Manager) GetSessionStore(sid string) (Store, error)

GetSessionStore Get SessionStore by its id.

func (*Manager) SessionDestroy Uses

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

SessionDestroy Destroy session by its id in http request cookie.

func (*Manager) SessionRegenerateID Uses

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

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

func (*Manager) SessionStart Uses

func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (Store, error)

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

func (*Manager) SetSecure Uses

func (manager *Manager) SetSecure(secure bool)

SetSecure Set cookie with https.

type ManagerConfig Uses

type ManagerConfig session.ManagerConfig

ManagerConfig define the session config

type MemProvider Uses

type MemProvider session.MemProvider

MemProvider Implement the provider interface

func (*MemProvider) SessionAll Uses

func (pder *MemProvider) SessionAll() int

SessionAll get count number of memory session

func (*MemProvider) SessionDestroy Uses

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

SessionDestroy delete session store in memory session by id

func (*MemProvider) SessionExist Uses

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

SessionExist check session store exist in memory session by sid

func (*MemProvider) SessionGC Uses

func (pder *MemProvider) SessionGC()

SessionGC clean expired session stores in memory session

func (*MemProvider) SessionInit Uses

func (pder *MemProvider) SessionInit(maxlifetime int64, savePath string) error

SessionInit init memory session

func (*MemProvider) SessionRead Uses

func (pder *MemProvider) SessionRead(sid string) (Store, error)

SessionRead get memory session store by sid

func (*MemProvider) SessionRegenerate Uses

func (pder *MemProvider) SessionRegenerate(oldsid, sid string) (Store, error)

SessionRegenerate generate new sid for session store in memory session

func (*MemProvider) SessionUpdate Uses

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

SessionUpdate expand time of session store by id in memory session

type MemSessionStore Uses

type MemSessionStore session.MemSessionStore

MemSessionStore memory session store. it saved sessions in a map in memory.

func (*MemSessionStore) Delete Uses

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

Delete in memory session by key

func (*MemSessionStore) Flush Uses

func (st *MemSessionStore) Flush() error

Flush clear all values in memory session

func (*MemSessionStore) Get Uses

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

Get value from memory session by key

func (*MemSessionStore) SessionID Uses

func (st *MemSessionStore) SessionID() string

SessionID get this id of memory session store

func (*MemSessionStore) SessionRelease Uses

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

SessionRelease Implement method, no used.

func (*MemSessionStore) Set Uses

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

Set value to memory session

type NewToOldStoreAdapter Uses

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

func (*NewToOldStoreAdapter) Delete Uses

func (n *NewToOldStoreAdapter) Delete(key interface{}) error

func (*NewToOldStoreAdapter) Flush Uses

func (n *NewToOldStoreAdapter) Flush() error

func (*NewToOldStoreAdapter) Get Uses

func (n *NewToOldStoreAdapter) Get(key interface{}) interface{}

func (*NewToOldStoreAdapter) SessionID Uses

func (n *NewToOldStoreAdapter) SessionID() string

func (*NewToOldStoreAdapter) SessionRelease Uses

func (n *NewToOldStoreAdapter) SessionRelease(w http.ResponseWriter)

func (*NewToOldStoreAdapter) Set Uses

func (n *NewToOldStoreAdapter) Set(key, value interface{}) error

type Provider Uses

type Provider interface {
    SessionInit(gclifetime int64, config string) error
    SessionRead(sid string) (Store, error)
    SessionExist(sid string) bool
    SessionRegenerate(oldsid, sid string) (Store, 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.

func GetProvider Uses

func GetProvider(name string) (Provider, error)

GetProvider

type Store Uses

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
}

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

func CreateNewToOldStoreAdapter Uses

func CreateNewToOldStoreAdapter(s session.Store) Store

Directories

PathSynopsis
couchbasePackage couchbase for session provider
ledisPackage ledis provide session Provider
memcachePackage memcache for session provider
mysqlPackage mysql for session provider
postgresPackage postgres for session provider
redisPackage redis for session provider
redis_clusterPackage redis for session provider
redis_sentinelPackage redis for session provider
ssdb

Package session imports 5 packages (graph) and is imported by 10 packages. Updated 2020-12-01. Refresh now. Tools for package owners.