Documentation
¶
Overview ¶
Package sessions implements HTTP sessions.
(Description TODO)
Index ¶
- func GenerateRandomKey(length int) []byte
- type Options
- type Session
- func (s *Session) Delete(w http.ResponseWriter, r *http.Request, key string) interface{}
- func (s *Session) Flash(w http.ResponseWriter, r *http.Request, key string, value interface{})
- func (s *Session) Flashes(w http.ResponseWriter, r *http.Request) map[string]interface{}
- func (s *Session) Get(r *http.Request, key string) interface{}
- func (s *Session) List(r *http.Request) map[string]interface{}
- func (s *Session) Reset(w http.ResponseWriter, r *http.Request)
- func (s *Session) Set(w http.ResponseWriter, r *http.Request, key string, value interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomKey ¶
GenerateRandomKey creates a random key with the given length in bytes. On failure, returns nil.
Note that keys created using `GenerateRandomKey()` are not automatically persisted. New keys will be created when the application is restarted, and previously issued cookies will not be able to be decoded.
Callers should explicitly check for the possibility of a nil return, treat it as a failure of the system random number generator, and not continue.
This function is an alias of securecookie.GenerateRandomKey, and is provided as a convenience method to avoid the additional import of the securecookie library.
Types ¶
type Options ¶
type Options struct {
// The name of the cookie (default is "_session").
Name string
// MaxAge of the cookie before expiry (default is 365 days). Set it to
// -1 for no expiry.
MaxAge int
}
Options to customize the behaviour of the session.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
A Session manages setting and getting data from the cookie that stores the session data.
func (*Session) Get ¶
Session creates a new session from the given HTTP request. If the request already has a cookie with an associated session, the session data is created from the cookie. If not, a new session is created.