Gorilla Sessions
Cookie and server-side session management for Go, with a pluggable registry of session stores.
Official Documentation ↗v1.2. Check the official docs for the latest API surface.Installation
go get github.com/gorilla/sessionsMethods
No methods match this filter.
Gorilla Sessions stores session values either in signed cookies or in a server-side store.
Key Features
- Cookie and filesystem stores
- Signed and encrypted cookies
- Flash messages and per-request session
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://pkg.go.dev/github.com/gorilla/sessions · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:03.878Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Note that in production code, we should check for errors when calling session.Save(r, w), and either display an error message or otherwise handle it. (https://pkg.go.dev/github.com/gorilla/sessions)
- Old sessions can still be read because the first pair will fail, and the second will be tested. (https://pkg.go.dev/github.com/gorilla/sessions)
- ResponseWriter ) error Save saves all sessions used during the current request. (https://pkg.go.dev/github.com/gorilla/sessions)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://pkg.go.dev/github.com/gorilla/sessions · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:03.878Z.
- This makes it easy to "rotate" secret keys and still be able to validate existing sessions. (https://pkg.go.dev/github.com/gorilla/sessions)
FAQ
- When should I use a server-side store?
- When session data is large or must be server-controlled. Cookie sessions are limited by the 4 KB cookie size and are client-visible.
- Is the cookie encrypted?
- Only when a second key is supplied. Providing just one key signs the cookie, so clients cannot tamper but can read it.
- Why is my session not persisting?
- Always call Save and ensure the response is not already written. Also confirm the keys are stable across processes.
Report a problem with this API docOpens a pre-filled issue on GitHub.