Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultSettings = SessionSettings{
Name: "SID",
StoreType: "InMemory",
MaxLifeTime: 86400,
LapseTime: 1800,
TokenKey: "Token",
TokenValue: "User-Agent",
}
DefaultSettings provides default values for session manager.
Functions ¶
func AvailableStoreTypes ¶
func AvailableStoreTypes() (list []string)
AvailableStoreTypes returns a slice of registered store types.
Types ¶
type Session ¶
type Session interface { Get(key interface{}) interface{} // gets session value Set(key, value interface{}) error // sets session value Delete(key interface{}) error // deletes session value }
Session stores session values.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
Session manager manages session and session store.
var Manager *SessionManager
Global session manager
func NewManager ¶
func NewManager(settings SessionSettings) *SessionManager
NewManager creates and returns new session manager object. It will start running GC at separate goroutine. SessionManager can only be created once.
func (*SessionManager) EndSession ¶
func (m *SessionManager) EndSession(rw http.ResponseWriter, r *http.Request)
EndSession closes session and remove it from session store.
func (*SessionManager) StartGC ¶
func (m *SessionManager) StartGC()
StartGC starts the GC for session manager.
func (*SessionManager) StartSession ¶
func (m *SessionManager) StartSession(rw http.ResponseWriter, r *http.Request) Session
StartSession returns existing session or creates new session if no matched.
func (*SessionManager) StopGC ¶
func (m *SessionManager) StopGC()
StopGC sends signal to stop the GC of session manager.
type SessionSettings ¶
type SessionSettings struct { Name string // name of session cookie StoreType string // session store type MaxLifeTime int // max lifetime for session, in second LapseTime int // lapse time for session id, in second // key value pair for session authentication // optional, will use default values if nil // default value: // TokenKey = "Token" // TokenValue = "User-Agent" TokenKey string // token key TokenValue string // token value, must be part of HTTP request header }
Settings of session manager.
type Store ¶
type Store interface { // find session object by session id, return nil if no such // session id Read(sid string) (Session, error) // creates new session according to session id and token // and insert it into persistence store Insert(sid string, token string) (Session, error) // replaces old session id by new id UpdateSID(old string, new string) // deletes session according to session id Delete(sid string) error // force GC to remove all sessions excess maxLifeTime, // count in seconds GC(maxLifeTime int) }
Store is the persistence store for session.
func NewStore ¶
func NewStore(storeType string, settings SessionSettings) Store
NewStore creates new store instance according to StoreType, returns nil if no such storeType.