Documentation
¶
Overview ¶
Package session provides session management capabilities.
Index ¶
- type Config
- type FileConfig
- type Manager
- type Session
- func (s *Session) Bytes(key string) ([]byte, bool)
- func (s *Session) CheckCSRF(key string, suspect string) bool
- func (s *Session) Flash(key string) string
- func (s *Session) Flush() error
- func (s *Session) Get(key string) (interface{}, bool)
- func (s *Session) Int(key string) (int, bool)
- func (s *Session) NewCSRF(key string) string
- func (s *Session) Remove(key string) bool
- func (s *Session) Set(key string, value interface{})
- func (s *Session) SetFlash(key string, message string)
- func (s *Session) String(key string) (string, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Type string `toml:"store"` HTTPSOnly bool `toml:"secure_only"` Secret string `toml:"secret"` FileConfig `toml:"file"` }
Config is the configuration for a session manager.
type FileConfig ¶
type FileConfig struct {
StoragePath string `toml:"storage_path"`
}
FileConfig represents a configuration for file-based sessions.
type Manager ¶
type Manager interface { // Get loads or creates a session for the given request. Get(*http.Request, http.ResponseWriter) (*Session, error) // Invalidate destroys any session related to the given request, if any. Invalidate(*http.Request, http.ResponseWriter) // Regenerate the given session, returning a new session or error. Regenerate(*Session, http.ResponseWriter) error // contains filtered or unexported methods }
A Manager handles loading and saving of sessions.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
A Session is a semi-persistent user storage container.
Sessions are created by the Session middleware. Each Session is expected to live for only the associated Request'c lifetime and are not designed to be operated on concurrently.
func (*Session) CheckCSRF ¶
CheckCSRF checks the given suspect token against the stored CSRF token.
Calling this method removes the value, if any, from the session.
func (*Session) Flash ¶
Flash returns the stored flash message with the given key or an empty string.
Calling this method removes the value stored in the session.
func (*Session) NewCSRF ¶
NewCSRF creates a one-time use random token to be used as a CSRF token.
Each form should contain a CSRF token that is generated when the form is shown and validated when a form is submitted.