Documentation ¶
Index ¶
- func DecodeGob(encoded []byte) (map[interface{}]interface{}, error)
- func EncodeGob(obj map[interface{}]interface{}) ([]byte, error)
- func RandomCreateBytes(n int, alphabets ...byte) []byte
- 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()
- func (manager *Manager) GetActiveSession() int
- func (manager *Manager) GetSessionStore(sid string) (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)
- func (manager *Manager) SetHashFunc(hasfunc, hashkey string)
- func (manager *Manager) SetSecure(secure bool)
- type Provider
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RandomCreateBytes ¶
RandomCreateBytes generate random []byte by specify chars.
Types ¶
type CookieProvider ¶
type CookieProvider struct {
// contains filtered or unexported fields
}
func (*CookieProvider) SessionAll ¶
func (pder *CookieProvider) SessionAll() int
Implement method, return 0.
func (*CookieProvider) SessionDestroy ¶
func (pder *CookieProvider) SessionDestroy(sid string) error
Method not implemented.
func (*CookieProvider) SessionExist ¶
func (pder *CookieProvider) SessionExist(sid string) bool
Cookie session is always existed
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 cookie string to map and put into SessionStore with sid.
func (*CookieProvider) SessionRegenerate ¶
func (pder *CookieProvider) SessionRegenerate(oldsid, sid string) (SessionStore, error)
Method not implemented.
func (*CookieProvider) SessionUpdate ¶
func (pder *CookieProvider) SessionUpdate(sid string) error
Method not implemented.
type CookieSessionStore ¶
type CookieSessionStore struct {
// contains filtered or unexported fields
}
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 where provider is an existing valid provider(e.g. "cookie") and a json config.
func (*Manager) GC ¶
func (manager *Manager) GC()
Start session gc process. it can do gc in times after gc lifetime.
func (*Manager) GetActiveSession ¶
Get all active sessions count number.
func (*Manager) GetSessionStore ¶
func (manager *Manager) GetSessionStore(sid string) (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)
Start session. generate or read the session id from http request. if session id exists, return SessionStore with this id.
func (*Manager) SetHashFunc ¶
Set hash function for generating session id.
type Provider ¶
type Provider interface { SessionInit(gclifetime int64, config string) error SessionRead(sid string) (SessionStore, error) SessionExist(sid string) bool SessionRegenerate(oldsid, sid string) (SessionStore, 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 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.