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, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "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(sid string) error
- func (pder *CookieProvider) SessionExist(sid string) bool
- func (pder *CookieProvider) SessionGC()
- func (pder *CookieProvider) SessionInit(maxlifetime int64, config string) error
- func (pder *CookieProvider) SessionRead(sid string) (SessionStore, error)
- func (pder *CookieProvider) SessionRegenerate(oldsid, sid string) (SessionStore, 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 appengine.Context)
- func (manager *Manager) GetActiveSession() int
- func (manager *Manager) GetSessionStore(sid string, c appengine.Context) (sessions SessionStore, err error)
- func (manager *Manager) SessionDestroy(w http.ResponseWriter, r *http.Request)
- func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Request) (session SessionStore)
- func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (session SessionStore, err error)
- func (manager *Manager) SetSecure(secure bool)
- type Provider
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CookieProvider ¶
type CookieProvider struct {
// contains filtered or unexported fields
}
Cookie session provider
func (*CookieProvider) SessionAll ¶
func (pder *CookieProvider) SessionAll() int
Implement method, return 0.
func (*CookieProvider) SessionDestroy ¶
func (pder *CookieProvider) SessionDestroy(sid string) error
Implement method, no used.
func (*CookieProvider) SessionExist ¶
func (pder *CookieProvider) SessionExist(sid string) bool
Cookie session is always existed
func (*CookieProvider) SessionGC ¶
func (pder *CookieProvider) SessionGC()
Implement method, no used.
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 cooke string to map and put into SessionStore with sid.
func (*CookieProvider) SessionRegenerate ¶
func (pder *CookieProvider) SessionRegenerate(oldsid, sid string) (SessionStore, error)
Implement method, no used.
func (*CookieProvider) SessionUpdate ¶
func (pder *CookieProvider) SessionUpdate(sid string) error
Implement method, no used.
type CookieSessionStore ¶
type CookieSessionStore struct {
// contains filtered or unexported fields
}
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
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 ¶
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 ¶
Get all active sessions count number.
func (*Manager) GetSessionStore ¶
func (manager *Manager) GetSessionStore(sid string, c appengine.Context) (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, err error)
Start session. 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(sid string, c appengine.Context) (SessionStore, error) SessionExist(sid string, c appengine.Context) bool SessionRegenerate(oldsid, sid string, c appengine.Context) (SessionStore, error) SessionDestroy(sid string, c appengine.Context) error SessionAll() int //get all active session SessionGC(c appengine.Context) }
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.
Directories ¶
Path | Synopsis |
---|---|
package mysql for session provider depends on github.com/go-sql-driver/mysql: go install github.com/go-sql-driver/mysql mysql session support need create table as sql: CREATE TABLE `session` ( `session_key` char(64) NOT NULL, session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Usage: import( _ "github.com/astaxie/beego/session/mysql" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("mysql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
|
package mysql for session provider depends on github.com/go-sql-driver/mysql: go install github.com/go-sql-driver/mysql mysql session support need create table as sql: CREATE TABLE `session` ( `session_key` char(64) NOT NULL, session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Usage: import( _ "github.com/astaxie/beego/session/mysql" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("mysql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md |