middleware

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 8 Imported by: 3 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartSession

func StartSession(manager *sessions.Manager, driver ...string) func(next http.Handler) http.Handler

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL