Documentation ¶
Overview ¶
Package sessions provides minimalist Go sessions, backed by a securecookie Store.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DebugCookieConfig = &CookieConfig{ Path: "/", MaxAge: defaultMaxAge, HTTPOnly: true, Secure: false, SameSite: http.SameSiteLaxMode, }
DebugCookieConfig configures http.Cookie creation for debugging. It does NOT require cookies be sent over HTTPS so it should only be used in development. Prefer DefaultCookieConfig.
var DefaultCookieConfig = &CookieConfig{ Path: "/", MaxAge: defaultMaxAge, HTTPOnly: true, Secure: true, SameSite: http.SameSiteLaxMode, }
DefaultCookieConfig configures http.Cookie creation for production.
Functions ¶
This section is empty.
Types ¶
type CookieConfig ¶ added in v0.3.0
type CookieConfig struct { // Cookie domain/path scope (leave zeroed for requested resource scope) // Defaults to the domain name of the responding server when unset Domain string // Defaults to the path of the responding URL when unset 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 // cookie may only be transferred over HTTPS. Recommend true. Secure bool // browser should prohibit non-HTTP (i.e. javascript) cookie access. Recommend true HTTPOnly bool // prohibit sending in cross-site requests with SameSiteLaxMode or SameSiteStrictMode SameSite http.SameSite }
CookieConfig configures http.Cookie creation.
type Session ¶
type Session[V any] struct { // contains filtered or unexported fields }
Session represents state values maintained in a sessions Store.
func NewSession ¶
NewSession returns a new Session.
func (*Session[V]) Destroy ¶
func (s *Session[V]) Destroy(w http.ResponseWriter)
Destroy destroys the session. Identical to calling store.Destroy(w, session.name).
func (*Session[V]) GetOk ¶ added in v0.3.0
GetOk returns the state value for the given key and whether they key exists.
type Store ¶
type Store[V any] interface { // New returns a new named Session New(name string) *Session[V] // Get a named Session from the request Get(req *http.Request, name string) (*Session[V], error) // Save writes a Session to the ResponseWriter Save(w http.ResponseWriter, session *Session[V]) error // Destroy removes (expires) a named Session Destroy(w http.ResponseWriter, name string) }
A Store manages creating, accessing, writing, and expiring Sessions.
func NewCookieStore ¶
func NewCookieStore[V any](config *CookieConfig, keyPairs ...[]byte) Store[V]
NewCookieStore returns a new Store that signs and optionally encrypts session state in http cookies.