Documentation ¶
Overview ¶
Package session provides support for sessions in web applications. It gives interface for specific session implementation. Session providers are implemented as specific packages. Max session life time, max session idle time, fixed time clearing are supported. See NewManager() function for specific session handling parameters.
Index ¶
- Constants
- func Register(name string, provide Provider)
- func WriteToLog(w io.Writer, s string, logLevel LogLevel)
- type LogLevel
- type Manager
- func (manager *Manager) CloseProvider()
- func (manager *Manager) DestroyAllSessions(l io.Writer, logLev LogLevel)
- func (manager *Manager) GetSessionIDLen() int
- func (manager *Manager) InitProvider(provParams []interface{}) error
- func (manager *Manager) SessionClose(sid string) error
- func (manager *Manager) SessionDestroy(sid string) error
- func (manager *Manager) SessionGC(l io.Writer, logLev LogLevel)
- func (manager *Manager) SessionStart(sid string) (Session, error)
- func (manager *Manager) SetMaxIdleTime(maxIdleTime int64)
- func (manager *Manager) SetMaxLifeTime(maxLifeTime int64)
- func (manager *Manager) SetSessionsKillTime(sessionsKillTime string) error
- func (manager *Manager) StartGC(l io.Writer, logLev LogLevel)
- func (manager *Manager) StopGC()
- type Provider
- type Session
Constants ¶
const ( TIME_SEC_LAYOUT = "15:04:05" TIME_MIN_LAYOUT = "15:04" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Manager ¶
type Manager struct { SessionsKillTime time.Time //clears all sessions // contains filtered or unexported fields }
Manager structure for holding provider.
func NewManager ¶
func NewManager(providerName string, maxLifeTime int64, maxIdleTime int64, sessionsKillTime string, provParams ...interface{}) (*Manager, error)
NewManager is a Manager create function. providerName is a name of the data storage provider. maxLifeTime is a maximum life of a session in seconds. maxIdleTime is a maximum idle time of a session in seconds. Idling is the time during which a session is not accessed. sessionsKillTime is a time in format 00:00 or 00:00:00 at which all sessions will be killed on dayly bases. See details how session destruction is handled in StartGC() provParams contains provider specific arguments.
func (*Manager) CloseProvider ¶
func (manager *Manager) CloseProvider()
InitProvider initializes provider with its specific parameters.
func (*Manager) DestroyAllSessions ¶
func (*Manager) GetSessionIDLen ¶
GetSessionIDLen returns session ID length specific for provider.
func (*Manager) InitProvider ¶
InitProvider initializes provider with its specific parameters. Should consult specific provider package to know its parameters.
func (*Manager) SessionClose ¶
SessionClose closes session with the given ID.
func (*Manager) SessionDestroy ¶
SessionDestroy destroys session by its ID.
func (*Manager) SessionStart ¶
SessionStart opens session with the given ID.
func (*Manager) SetMaxIdleTime ¶
SetMaxIdleTime is an alias for provider SetMaxIdleTime
func (*Manager) SetMaxLifeTime ¶
SetMaxLifeTime is an alias for provider SetMaxLifeTime
func (*Manager) SetSessionsKillTime ¶
SetSessionsKillTime sets time from the given string value
func (*Manager) StartGC ¶
StartGC starts garbage collection (GC) server for managing sessions destruction. Session can be destroyed:
- if SessionsKillTime is set, then all sessions will be cleared at that time.
- if idle time is set, then sessions idling (session access time is controled) more then that time will be cleared.
- if max life time is set, then sessions will live no more then that specified time, no matter idling or not.
SessionsKillTime runs its own independant gorouting. MaxLifeTime and MaxIdleTime are combined in one gorouting. All thee parameters can be used together. Goroutings are controled by a context an can be cancelled. So it is possible to modify SessionsKillTime/MaxLifeTime/MaxIdleTime and to restart the GC server Server does not generate any output. Instead all errors/comments are sent to io.Writer passed as argument to StartGC() function.
type Provider ¶
type Provider interface { InitProvider(provParams []interface{}) error CloseProvider() SessionInit(sid string) (Session, error) SessionRead(sid string) (Session, error) SessionDestroy(sid string) error SessionClose(sid string) error SessionGC(io.Writer, LogLevel) GetSessionIDLen() int SetMaxLifeTime(int64) GetMaxLifeTime() int64 SetMaxIdleTime(int64) GetMaxIdleTime() int64 DestroyAllSessions(io.Writer, LogLevel) }
Provider interface for session provider.
type Session ¶
type Session interface { Set(key string, value interface{}) error //set session value Put(key string, value interface{}) error //set session value and flushes Get(key string, value interface{}) error //get session value GetBool(key string) bool //get bool session value, false if no key or assertion error GetString(key string) string //get string session value, empty string if no key or assertion error GetInt(key string) int64 //get int64 session value, 0 if no key or assertion error GetFloat(key string) float64 //get float64 session value, 0.0 if no key or assertion error Delete(key string) error //delete session value SessionID() string //returns current sessionID Flush() error //flushes data to persistent storage TimeCreated() time.Time TimeAccessed() time.Time }
Session interface for session functionality.
Directories ¶
Path | Synopsis |
---|---|
Package pg contains postgresql session provider based on jackc connection to PG.
|
Package pg contains postgresql session provider based on jackc connection to PG. |
Package redis contains postgresql session provider based on go-redis client.
|
Package redis contains postgresql session provider based on go-redis client. |
Package sqlite contains postgresql session provider based on jackc connection to PG.
|
Package sqlite contains postgresql session provider based on jackc connection to PG. |