Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StartSession ¶
StartSession is an example middleware that starts a session for each request. If this middleware not suitable for your application, you can create your own.
func StartSessionWithConfig ¶ added in v1.5.0
func StartSessionWithConfig(manager *sessions.Manager, cfg Config) func(next http.Handler) http.Handler
StartSessionWithConfig is StartSession with explicit configuration.
The response is not buffered. The session is saved and its cookie (re)sent right before the response header goes out: on the handler's first WriteHeader, Write or Flush, or when it returns without having written anything. The cookie is only sent when that save succeeded, so its expiry slides along with the server-side lifetime.
Changes made after the header went out are still persisted when the handler returns, but can no longer affect the cookie. A session ID that is regenerated that late cannot reach the client and is not stored. When the save before the header fails, the session is not saved again.
The first write reads the session, so it must not run concurrently with changes to it.
Types ¶
type Config ¶ added in v1.5.0
type Config struct {
// Driver is the session driver name; empty selects the default driver.
Driver string
// Cookie, when set, is called with the prepared session cookie before it
// is written, allowing customization of Path, Domain, Secure, SameSite
// and the other attributes.
Cookie func(*http.Cookie)
}
Config customizes the StartSession middleware.