Documentation ¶
Index ¶
- Variables
- func DecodeGob(encoded []byte) (map[interface{}]interface{}, error)
- func EncodeGob(obj map[interface{}]interface{}) ([]byte, error)
- func NewSession(driver string, config *ManagerConfig) (err error)
- func Register(name string, provide Provider)
- type BlankSessionStore
- func (st *BlankSessionStore) Delete(key interface{}) (err error)
- func (st *BlankSessionStore) Flush() (err error)
- func (st *BlankSessionStore) Get(key interface{}) (value interface{})
- func (st *BlankSessionStore) SessionID() (sid string)
- func (st *BlankSessionStore) SessionRelease(w http.ResponseWriter) (err error)
- func (st *BlankSessionStore) Set(key, value interface{}) (err error)
- 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, r *http.Request) (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) error
- func (st *CookieSessionStore) Set(key, value interface{}) error
- type Log
- type Manager
- func (manager *Manager) GC()
- func (manager *Manager) GetActiveSession() int
- func (manager *Manager) GetProvider() Provider
- func (manager *Manager) GetSessionStore(sid string, r *http.Request) (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 ManagerConfig
- type Provider
- type RedisProvider
- func (pder *RedisProvider) SessionAll() int
- func (pder *RedisProvider) SessionDestroy(sid string) error
- func (pder *RedisProvider) SessionExist(sid string) bool
- func (pder *RedisProvider) SessionGC()
- func (pder *RedisProvider) SessionInit(maxlifetime int64, config string) error
- func (pder *RedisProvider) SessionRead(sid string, r *http.Request) (Store, error)
- func (pder *RedisProvider) SessionRegenerate(oldsid, sid string) (Store, error)
- type RedisSessionStore
- func (st *RedisSessionStore) Delete(key interface{}) (err error)
- func (st *RedisSessionStore) Flush() (err error)
- func (st *RedisSessionStore) Get(key interface{}) (value interface{})
- func (st *RedisSessionStore) SessionID() (sid string)
- func (st *RedisSessionStore) SessionRelease(w http.ResponseWriter) (err error)
- func (st *RedisSessionStore) Set(key, value interface{}) (err error)
- type SessionHandler
- type Store
Constants ¶
This section is empty.
Variables ¶
var SLogger = NewSessionLog(os.Stderr)
SLogger a helpful variable to log information about session
Functions ¶
func NewSession ¶
func NewSession(driver string, config *ManagerConfig) (err error)
NewSession 注册session
Types ¶
type BlankSessionStore ¶
type BlankSessionStore struct { }
BlankSessionStore 空session驱动 用于未开启session时相关操作,避免空指针异常
func (*BlankSessionStore) Delete ¶
func (st *BlankSessionStore) Delete(key interface{}) (err error)
func (*BlankSessionStore) Flush ¶
func (st *BlankSessionStore) Flush() (err error)
func (*BlankSessionStore) Get ¶
func (st *BlankSessionStore) Get(key interface{}) (value interface{})
func (*BlankSessionStore) SessionID ¶
func (st *BlankSessionStore) SessionID() (sid string)
func (*BlankSessionStore) SessionRelease ¶
func (st *BlankSessionStore) SessionRelease(w http.ResponseWriter) (err error)
func (*BlankSessionStore) Set ¶
func (st *BlankSessionStore) Set(key, value interface{}) (err error)
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 ¶
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) error
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 Log ¶
Log implement the log.Logger
func NewSessionLog ¶
NewSessionLog set io.Writer to create a Logger for session.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager contains Provider and its configuration.
func NewManager ¶
func NewManager(provideName string, cf *ManagerConfig) (*Manager, error)
NewManager Create new Manager with provider name and json config string. provider name: 1. cookie 2. redis
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) GetProvider ¶
GetProvider return current manager's provider
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 ManagerConfig ¶
type ManagerConfig struct { CookieName string `json:"cookieName"` EnableSetCookie bool `json:"enableSetCookie,omitempty"` Gclifetime int64 `json:"gclifetime"` Maxlifetime int64 `json:"maxLifetime"` DisableHTTPOnly bool `json:"disableHTTPOnly"` Secure bool `json:"secure"` CookieLifeTime int `json:"cookieLifeTime"` ProviderConfig string `json:"providerConfig"` Domain string `json:"domain"` SessionIDLength int64 `json:"sessionIDLength"` EnableSidInHTTPHeader bool `json:"EnableSidInHTTPHeader"` SessionNameInHTTPHeader string `json:"SessionNameInHTTPHeader"` EnableSidInURLQuery bool `json:"EnableSidInURLQuery"` SessionIDPrefix string `json:"sessionIDPrefix"` }
ManagerConfig define the session config
type Provider ¶
type Provider interface { SessionInit(gclifetime int64, config string) error SessionRead(sid string, r *http.Request) (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 RedisProvider ¶ added in v0.1.7
type RedisProvider struct {
// contains filtered or unexported fields
}
func (*RedisProvider) SessionAll ¶ added in v0.1.7
func (pder *RedisProvider) SessionAll() int
SessionAll Implement method, return 0.
func (*RedisProvider) SessionDestroy ¶ added in v0.1.7
func (pder *RedisProvider) SessionDestroy(sid string) error
SessionDestroy Implement method, no used.
func (*RedisProvider) SessionExist ¶ added in v0.1.7
func (pder *RedisProvider) SessionExist(sid string) bool
SessionExist Redis session is always existed
func (*RedisProvider) SessionGC ¶ added in v0.1.7
func (pder *RedisProvider) SessionGC()
SessionGC Implement method, no used.
func (*RedisProvider) SessionInit ¶ added in v0.1.7
func (pder *RedisProvider) SessionInit(maxlifetime int64, config string) error
func (*RedisProvider) SessionRead ¶ added in v0.1.7
func (*RedisProvider) SessionRegenerate ¶ added in v0.1.7
func (pder *RedisProvider) SessionRegenerate(oldsid, sid string) (Store, error)
SessionRegenerate Implement method, no used.
type RedisSessionStore ¶ added in v0.1.7
type RedisSessionStore struct {
// contains filtered or unexported fields
}
RedisSessionStore session存储到redis中
func (*RedisSessionStore) Delete ¶ added in v0.1.7
func (st *RedisSessionStore) Delete(key interface{}) (err error)
func (*RedisSessionStore) Flush ¶ added in v0.1.7
func (st *RedisSessionStore) Flush() (err error)
func (*RedisSessionStore) Get ¶ added in v0.1.7
func (st *RedisSessionStore) Get(key interface{}) (value interface{})
func (*RedisSessionStore) SessionID ¶ added in v0.1.7
func (st *RedisSessionStore) SessionID() (sid string)
func (*RedisSessionStore) SessionRelease ¶ added in v0.1.7
func (st *RedisSessionStore) SessionRelease(w http.ResponseWriter) (err error)
func (*RedisSessionStore) Set ¶ added in v0.1.7
func (st *RedisSessionStore) Set(key, value interface{}) (err error)
type SessionHandler ¶
type SessionHandler struct {
// contains filtered or unexported fields
}
func (*SessionHandler) Get ¶
func (s *SessionHandler) Get(key interface{}) interface{}
func (*SessionHandler) Set ¶
func (s *SessionHandler) Set(key, value interface{}) error
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) error // 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 SessionStart ¶
SessionStart 启动session