Documentation ¶
Overview ¶
Package session provides HTTP cookie session implementations.
See SessionManager.Handler() method for code example.
Index ¶
Constants ¶
const SessionIdCookieName = "__sessionid"
SessionIdCookieName is the cookie name of session id.
const SessionIdLength int = 32
SessionIdLength is the length of session id.
const SessionIdRunes string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
SessionIdRunes are the characters of which the session id consists.
Variables ¶
This section is empty.
Functions ¶
func HTTPHandler ¶
HTTPHandler adapts Handler to http.Handler
func HTTPHandlerFunc ¶
func HTTPHandlerFunc(f HandlerFunc) http.Handler
HTTPHandlerFunc adapts HandlerFunc to http.Handler
Types ¶
type Handler ¶
type Handler interface {
ServeHTTP(r http.ResponseWriter, w *http.Request, session Session)
}
Object implementing Handler interface can be used to access session value while serving http.
Function HTTPHandler(Handler) wraps a Handler to http.Handler.
type HandlerFunc ¶
type HandlerFunc func(r http.ResponseWriter, w *http.Request, session Session)
The HandlerFunc type is an adapter to allow the use of ordinary functions as Handler.
func (HandlerFunc) ServeHTTP ¶
func (f HandlerFunc) ServeHTTP(r http.ResponseWriter, w *http.Request, session Session)
ServeHTTP calls f(r, w, session).
type ResponseWriterWrapper ¶
type ResponseWriterWrapper interface {
GetResponseWriter() http.ResponseWriter
}
ResponseWriterWrapper is implemented by the http.ResponseWriter object passed to Handler.ServeHTTP or HandlerFunc. You can cast the ResponseWriter to this interface to get the real ResponseWriter.
For example:
func fooHandler(w http.ResponseWriter, r *http.Request, s session.Session) { if wrapper, ok := w.(session.ResponseWriterWrapper); ok { realWriter := wrapper.GetResponseWriter() // Do any thing to realWriter. } }
type Session ¶
type Session interface { // Id returns the session id. Id() string // Value returns the value associated with the session id. Value() interface{} // SetValue sets the vlaue associated with the session id. SetValue(value interface{}) // AddSessionId adds session id query to the URL. The parameter url is altered // and returned. AddSessionId(url *url.URL) *url.URL }
Objects implementing Session interface can be used to get and set session value.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func NewSessionManager ¶
func NewSessionManager() *SessionManager
func (*SessionManager) Cleanup ¶
func (s *SessionManager) Cleanup(idle time.Duration)
Cleanup deletes any sessions that have been idle at least for some duration.
func (*SessionManager) Handler ¶
func (s *SessionManager) Handler(handler http.Handler) http.Handler
Handler wrapps a http.Handler to do session management.
func (*SessionManager) InvalidateSession ¶
func (s *SessionManager) InvalidateSession(id string)
InvalidateSession makes a session invalidate. New session will be allocated at the next request.