Documentation ¶
Overview ¶
Package session offers a HTTP handler to manage web sessions using encrypted and authenticated cookies as well as pluggable backing stores.
Index ¶
- func Handler(h http.Handler, opts ...option) http.Handler
- func Register(id int8, value interface{})
- func WithDomain(d string) option
- func WithMaxAge(d time.Duration) option
- func WithName(n string) option
- func WithSecretKey(k ...string) option
- func WithStore(store Store) option
- type Session
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler verifies and creates new sessions. If a session is found and valid, it is attached to the Request's context for further modification or retrieval by other handlers. Sessions are automatically saved before sending the response.
func Register ¶
func Register(id int8, value interface{})
Register registers custom struct types that are going to be stored in the sessions. It allows to retrive struct types from the session and do type assertions on them as opposed to map values.
func WithDomain ¶
func WithDomain(d string) option
WithDomain allows setting the cookie name for storing the session.
func WithMaxAge ¶
WithMaxAge allows to set the duration of the session.
func WithName ¶
func WithName(n string) option
WithName allows setting the cookie name for storing the session.
func WithSecretKey ¶
func WithSecretKey(k ...string) option
WithSecretKey allows to configure the secret key to encrypt and authenticate the session data. Key rotation is supported, the left-most key is always the current key.
Types ¶
type Session ¶
Session represents a secure session cookie. By default, it stores session data in the session cookie. If a Store is provided, only the session ID is stored in the session cookie.
func FromContext ¶
FromContext extracts the session from the given context.
func (*Session) Destroy ¶
func (s *Session) Destroy()
Destroy signals the user's browser to remove the session cookie.
type Store ¶
type Store interface { // Load retrieves opaque session data from backing store Load(id string) ([]byte, error) // Saves persists opaque session data to backing store Save(id string, data []byte) error // Destroy removes the session altogether from backing store Destroy(id string) error }
Store defines the contract for implementing different session data stores.