Documentation ¶
Overview ¶
Package session provider
Usage: import(
"github.com/prima101112/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(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) (Store, error)
- func (pder *CookieProvider) SessionRegenerate(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 FileProvider
- func (fp *FileProvider) SessionAll() int
- func (fp *FileProvider) SessionDestroy(sid string) error
- func (fp *FileProvider) SessionExist(sid string) bool
- func (fp *FileProvider) SessionGC()
- func (fp *FileProvider) SessionInit(maxlifetime int64, savePath string) error
- func (fp *FileProvider) SessionRead(sid string) (Store, error)
- func (fp *FileProvider) SessionRegenerate(oldsid, sid string) (Store, error)
- type FileSessionStore
- func (fs *FileSessionStore) Delete(key interface{}) error
- func (fs *FileSessionStore) Flush() error
- func (fs *FileSessionStore) Get(key interface{}) interface{}
- func (fs *FileSessionStore) SessionID() string
- func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter)
- func (fs *FileSessionStore) Set(key, value interface{}) error
- type Manager
- func (manager *Manager) GC()
- func (manager *Manager) GetActiveSession() int
- func (manager *Manager) GetSessionStore(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 MemProvider
- func (pder *MemProvider) SessionAll() int
- func (pder *MemProvider) SessionDestroy(sid string) error
- func (pder *MemProvider) SessionExist(sid string) bool
- func (pder *MemProvider) SessionGC()
- func (pder *MemProvider) SessionInit(maxlifetime int64, savePath string) error
- func (pder *MemProvider) SessionRead(sid string) (Store, error)
- func (pder *MemProvider) SessionRegenerate(oldsid, sid string) (Store, error)
- func (pder *MemProvider) SessionUpdate(sid string) error
- type MemSessionStore
- func (st *MemSessionStore) Delete(key interface{}) error
- func (st *MemSessionStore) Flush() error
- func (st *MemSessionStore) Get(key interface{}) interface{}
- func (st *MemSessionStore) SessionID() string
- func (st *MemSessionStore) SessionRelease(w http.ResponseWriter)
- func (st *MemSessionStore) Set(key, value interface{}) error
- 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(sid string) error
SessionDestroy Implement method, no used.
func (*CookieProvider) SessionExist ¶
func (pder *CookieProvider) SessionExist(sid string) bool
SessionExist Cookie session is always existed
func (*CookieProvider) SessionGC ¶
func (pder *CookieProvider) SessionGC()
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 ¶
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 ¶
func (pder *CookieProvider) SessionRegenerate(oldsid, sid string) (Store, error)
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 FileProvider ¶
type FileProvider struct {
// contains filtered or unexported fields
}
FileProvider File session provider
func (*FileProvider) SessionAll ¶
func (fp *FileProvider) SessionAll() int
SessionAll Get active file session number. it walks save path to count files.
func (*FileProvider) SessionDestroy ¶
func (fp *FileProvider) SessionDestroy(sid string) error
SessionDestroy Remove all files in this save path
func (*FileProvider) SessionExist ¶
func (fp *FileProvider) SessionExist(sid string) bool
SessionExist Check file session exist. it checkes the file named from sid exist or not.
func (*FileProvider) SessionGC ¶
func (fp *FileProvider) SessionGC()
SessionGC Recycle files in save path
func (*FileProvider) SessionInit ¶
func (fp *FileProvider) SessionInit(maxlifetime int64, savePath string) error
SessionInit Init file session provider. savePath sets the session files path.
func (*FileProvider) SessionRead ¶
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 ¶
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 ¶
type FileSessionStore struct {
// contains filtered or unexported fields
}
FileSessionStore File session store
func (*FileSessionStore) Delete ¶
func (fs *FileSessionStore) Delete(key interface{}) error
Delete value in file session by given key
func (*FileSessionStore) Flush ¶
func (fs *FileSessionStore) Flush() error
Flush Clean all values in file session
func (*FileSessionStore) Get ¶
func (fs *FileSessionStore) Get(key interface{}) interface{}
Get value from file session
func (*FileSessionStore) SessionID ¶
func (fs *FileSessionStore) SessionID() string
SessionID Get file session store id
func (*FileSessionStore) SessionRelease ¶
func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter)
SessionRelease Write file session to local file with Gob string
func (*FileSessionStore) Set ¶
func (fs *FileSessionStore) Set(key, value interface{}) error
Set value to file session
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) GC ¶
func (manager *Manager) GC()
GC Start session gc process. it can do gc in times after gc lifetime.
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 ¶
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 MemProvider ¶
type MemProvider struct {
// contains filtered or unexported fields
}
MemProvider Implement the provider interface
func (*MemProvider) SessionAll ¶
func (pder *MemProvider) SessionAll() int
SessionAll get count number of memory session
func (*MemProvider) SessionDestroy ¶
func (pder *MemProvider) SessionDestroy(sid string) error
SessionDestroy delete session store in memory session by id
func (*MemProvider) SessionExist ¶
func (pder *MemProvider) SessionExist(sid string) bool
SessionExist check session store exist in memory session by sid
func (*MemProvider) SessionGC ¶
func (pder *MemProvider) SessionGC()
SessionGC clean expired session stores in memory session
func (*MemProvider) SessionInit ¶
func (pder *MemProvider) SessionInit(maxlifetime int64, savePath string) error
SessionInit init memory session
func (*MemProvider) SessionRead ¶
func (pder *MemProvider) SessionRead(sid string) (Store, error)
SessionRead get memory session store by sid
func (*MemProvider) SessionRegenerate ¶
func (pder *MemProvider) SessionRegenerate(oldsid, sid string) (Store, error)
SessionRegenerate generate new sid for session store in memory session
func (*MemProvider) SessionUpdate ¶
func (pder *MemProvider) SessionUpdate(sid string) error
SessionUpdate expand time of session store by id in memory session
type MemSessionStore ¶
type MemSessionStore struct {
// contains filtered or unexported fields
}
MemSessionStore memory session store. it saved sessions in a map in memory.
func (*MemSessionStore) Delete ¶
func (st *MemSessionStore) Delete(key interface{}) error
Delete in memory session by key
func (*MemSessionStore) Flush ¶
func (st *MemSessionStore) Flush() error
Flush clear all values in memory session
func (*MemSessionStore) Get ¶
func (st *MemSessionStore) Get(key interface{}) interface{}
Get value from memory session by key
func (*MemSessionStore) SessionID ¶
func (st *MemSessionStore) SessionID() string
SessionID get this id of memory session store
func (*MemSessionStore) SessionRelease ¶
func (st *MemSessionStore) SessionRelease(w http.ResponseWriter)
SessionRelease Implement method, no used.
func (*MemSessionStore) Set ¶
func (st *MemSessionStore) Set(key, value interface{}) error
Set value to memory session
type Provider ¶
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.
type Store ¶
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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package couchbase for session provider depend on github.com/couchbaselabs/go-couchbasee go install github.com/couchbaselabs/go-couchbase Usage: import( _ "github.com/prima101112/beego/session/couchbase" "github.com/prima101112/beego/session" ) func init() { globalSessions, _ = session.NewManager("couchbase", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
|
Package couchbase for session provider depend on github.com/couchbaselabs/go-couchbasee go install github.com/couchbaselabs/go-couchbase Usage: import( _ "github.com/prima101112/beego/session/couchbase" "github.com/prima101112/beego/session" ) func init() { globalSessions, _ = session.NewManager("couchbase", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md |
Package ledis provide session Provider
|
Package ledis provide session Provider |
Package memcache for session provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/prima101112/beego/session/memcache" "github.com/prima101112/beego/session" ) func init() { globalSessions, _ = session.NewManager("memcache", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
|
Package memcache for session provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/prima101112/beego/session/memcache" "github.com/prima101112/beego/session" ) func init() { globalSessions, _ = session.NewManager("memcache", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}“) 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/prima101112/beego/session/mysql" "github.com/prima101112/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/prima101112/beego/session/mysql" "github.com/prima101112/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 postgres for session provider depends on github.com/lib/pq: go install github.com/lib/pq needs this table in your database: CREATE TABLE session ( session_key char(64) NOT NULL, session_data bytea, session_expiry timestamp NOT NULL, CONSTRAINT session_key PRIMARY KEY(session_key) ); will be activated with these settings in app.conf: SessionOn = true SessionProvider = postgresql SessionSavePath = "user=a password=b dbname=c sslmode=disable" SessionName = session Usage: import( _ "github.com/prima101112/beego/session/postgresql" "github.com/prima101112/beego/session" ) func init() { globalSessions, _ = session.NewManager("postgresql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
|
Package postgres for session provider depends on github.com/lib/pq: go install github.com/lib/pq needs this table in your database: CREATE TABLE session ( session_key char(64) NOT NULL, session_data bytea, session_expiry timestamp NOT NULL, CONSTRAINT session_key PRIMARY KEY(session_key) ); will be activated with these settings in app.conf: SessionOn = true SessionProvider = postgresql SessionSavePath = "user=a password=b dbname=c sslmode=disable" SessionName = session Usage: import( _ "github.com/prima101112/beego/session/postgresql" "github.com/prima101112/beego/session" ) func init() { globalSessions, _ = session.NewManager("postgresql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md |
Package redis for session provider depend on github.com/garyburd/redigo/redis go install github.com/garyburd/redigo/redis Usage: import( _ "github.com/prima101112/beego/session/redis" "github.com/prima101112/beego/session" ) func init() { globalSessions, _ = session.NewManager("redis", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
|
Package redis for session provider depend on github.com/garyburd/redigo/redis go install github.com/garyburd/redigo/redis Usage: import( _ "github.com/prima101112/beego/session/redis" "github.com/prima101112/beego/session" ) func init() { globalSessions, _ = session.NewManager("redis", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md |