Documentation ¶
Overview ¶
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 ¶
- func DecodeGob(encoded []byte) (map[interface{}]interface{}, error)
- func EncodeGob(obj map[interface{}]interface{}) ([]byte, error)
- func Register(name string, provide Provider)
- type CookieProvider
- func (pder *CookieProvider) SessionAll() int
- func (pder *CookieProvider) SessionDestroy(c context.Context, sid string) error
- func (pder *CookieProvider) SessionExist(c context.Context, sid string) bool
- func (pder *CookieProvider) SessionGC(c context.Context)
- func (pder *CookieProvider) SessionInit(maxlifetime int64, config string) error
- func (pder *CookieProvider) SessionRead(c context.Context, sid string) (Store, error)
- func (pder *CookieProvider) SessionRegenerate(c context.Context, oldsid, sid string) (Store, error)
- func (pder *CookieProvider) SessionUpdate(sid string) error
- type CookieSessionStore
- func (st *CookieSessionStore) Delete(key interface{}) error
- func (st *CookieSessionStore) Flush() error
- func (st *CookieSessionStore) Get(key interface{}) interface{}
- func (st *CookieSessionStore) SessionID() string
- func (st *CookieSessionStore) SessionRelease(w http.ResponseWriter)
- func (st *CookieSessionStore) Set(key, value interface{}) error
- type Manager
- func (manager *Manager) GC(c context.Context)
- func (manager *Manager) GetActiveSession() int
- func (manager *Manager) GetSessionStore(c context.Context, sid string) (sessions Store, err error)
- func (manager *Manager) SessionDestroy(w http.ResponseWriter, r *http.Request)
- func (manager *Manager) SessionRegenerateID(w http.ResponseWriter, r *http.Request) (session Store)
- func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (session Store, err error)
- func (manager *Manager) SetSecure(secure bool)
- type Provider
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CookieProvider ¶
type CookieProvider struct {
// contains filtered or unexported fields
}
CookieProvider Cookie session provider
func (*CookieProvider) SessionAll ¶
func (pder *CookieProvider) SessionAll() int
SessionAll Implement method, return 0.
func (*CookieProvider) SessionDestroy ¶
func (pder *CookieProvider) SessionDestroy(c context.Context, sid string) error
SessionDestroy Implement method, no used.
func (*CookieProvider) SessionExist ¶
func (pder *CookieProvider) SessionExist(c context.Context, sid string) bool
SessionExist Cookie session is always existed
func (*CookieProvider) SessionGC ¶
func (pder *CookieProvider) SessionGC(c context.Context)
SessionGC Implement method, no used.
func (*CookieProvider) SessionInit ¶
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 ¶
SessionRead Get SessionStore in cooke. decode cooke string to map and put into SessionStore with sid.
func (*CookieProvider) SessionRegenerate ¶
SessionRegenerate Implement method, no used.
func (*CookieProvider) SessionUpdate ¶
func (pder *CookieProvider) SessionUpdate(sid string) error
SessionUpdate Implement method, no used.
type CookieSessionStore ¶
type CookieSessionStore struct {
// contains filtered or unexported fields
}
CookieSessionStore Cookie SessionStore
func (*CookieSessionStore) Delete ¶
func (st *CookieSessionStore) Delete(key interface{}) error
Delete value in cookie session
func (*CookieSessionStore) Flush ¶
func (st *CookieSessionStore) Flush() error
Flush 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
SessionID Return id of this cookie session
func (*CookieSessionStore) SessionRelease ¶
func (st *CookieSessionStore) SessionRelease(w http.ResponseWriter)
SessionRelease 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 ¶
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) GetActiveSession ¶
GetActiveSession Get all active sessions count number.
func (*Manager) GetSessionStore ¶
GetSessionStore Get SessionStore by its id.
func (*Manager) SessionDestroy ¶
func (manager *Manager) SessionDestroy(w http.ResponseWriter, r *http.Request)
SessionDestroy Destroy session by its id in http request cookie.
func (*Manager) SessionRegenerateID ¶ added in v1.6.1
SessionRegenerateID 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 Store, err error)
SessionStart generate or read the session id from http request. if session id exists, return SessionStore with this id.
type Provider ¶
type Provider interface { SessionInit(gclifetime int64, config string) error SessionRead(c context.Context, sid string) (Store, error) SessionExist(c context.Context, sid string) bool SessionRegenerate(c context.Context, oldsid, sid string) (Store, error) SessionDestroy(c context.Context, sid string) error SessionAll() int //get all active session SessionGC(c context.Context) }
Provider contains global session methods and saved SessionStores. it can operate a SessionStore by its id.
type Store ¶ added in v1.6.1
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.