Documentation ¶
Overview ¶
Package sessions provides minimalist Go sessions, backed by a securecookie Store.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // cookie domain/path scope (leave zeroed for requested resource scope) Domain string Path string // MaxAge=0 means no 'Max-Age' attribute specified. // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. // MaxAge>0 means Max-Age attribute present and given in seconds. MaxAge int // browser should prohibit non-HTTP (i.e. javascript) cookie access HTTPOnly bool // cookie may only be transferred over HTTPS Secure bool // prohibit sending in cross-site requests with SameSiteLaxMode or SameSiteLaxMode SameSite http.SameSite }
Config is the set of cookie properties.
type CookieStore ¶
type CookieStore struct { // encodes and decodes signed and optionally encrypted cookie values Codecs []securecookie.Codec // configures session cookie properties of new Sessions Config *Config }
CookieStore stores Sessions in secure cookies (i.e. client-side)
func NewCookieStore ¶
func NewCookieStore(keyPairs ...[]byte) *CookieStore
NewCookieStore returns a new CookieStore which signs and optionally encrypts session cookies.
func (*CookieStore) Destroy ¶
func (s *CookieStore) Destroy(w http.ResponseWriter, name string)
Destroy deletes the Session with the given name by issuing an expired session cookie with the same name.
func (*CookieStore) Get ¶
Get returns the named Session from the Request. Returns an error if the session cookie cannot be found, the cookie verification fails, or an error occurs decoding the cookie value.
func (*CookieStore) New ¶
func (s *CookieStore) New(name string) *Session
New returns a new Session with the requested name and the store's config value.
func (*CookieStore) Save ¶
func (s *CookieStore) Save(w http.ResponseWriter, session *Session) error
Save adds or updates the Session on the response via a signed and optionally encrypted session cookie. Session Values are encoded into the cookie value and the session Config sets cookie properties.
type Session ¶
type Session struct { Config *Config // session cookie config Values map[string]interface{} // contains filtered or unexported fields }
Session represents Values state which a named bundle of maintained web state stores web session state
func NewSession ¶
NewSession returns a new Session.
func (*Session) Destroy ¶
func (s *Session) Destroy(w http.ResponseWriter)
Destroy destroys the session. Identical to calling store.Destroy(w, session.name).