sessions

Cookie and filesystem session management for Go's net/http, with pluggable backends and key rotation.

Library
Go
vv1.4.0
3,149stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
48/100Fair
Development Activity0
Maintenance20
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture84
Code Quality85
Innovation55
Learning Curve65

gorilla/sessions provides cookie-based and filesystem-based HTTP session storage for Go’s net/http, along with the infrastructure to build custom backends. It wraps gorilla/securecookie to sign and optionally encrypt session data, exposes a Session type with typed helpers for flash messages, and lets a single request read from and save to multiple session stores at once through a shared Registry.

The package defines a small Store interface — Get, New, and Save — that the community has implemented for most major datastores, including Redis, PostgreSQL, MySQL, MongoDB, DynamoDB, and BoltDB, making it straightforward to swap the bundled CookieStore or FilesystemStore for a production-grade backend without changing handler code. It has shipped as part of the Gorilla web toolkit since 2012 and is a de facto standard for session handling in idiomatic Go HTTP services.

What You Get

  • CookieStore for signed and optionally AES-encrypted session cookies via gorilla/securecookie
  • FilesystemStore for server-side session storage with automatic file cleanup on expiry
  • A Store interface (Get/New/Save) so custom backends plug in without touching handler code
  • Cross-request Registry that lets multiple named sessions be fetched and saved together with sessions.Save(r, w)
  • Flash message helpers (AddFlash/Flashes) for one-time post-redirect notices
  • Built-in key rotation support for rotating authentication and encryption keys without invalidating existing sessions

Common Use Cases

  • Storing a logged-in user’s identity and CSRF token in a signed cookie for a Go web app
  • Persisting flash messages across a redirect after a form submission
  • Swapping the default cookie store for a Redis- or Postgres-backed Store in production deployments
  • Managing multiple independent sessions (e.g. auth session + preferences session) in one request

Under The Hood

Architecture The package centers on three thin abstractions: Session (the per-request value bag with Values, Options, and IsNew), Store (the Get/New/Save contract implemented by CookieStore and FilesystemStore in store.go), and Registry (sessions.go), which caches decoded sessions on the request’s context via GetRegistry(r) so repeated store.Get() calls within a handler don’t re-decode cookie data, and lets sessions.Save(r, w) flush every registered session in one call. CookieStore delegates all signing/encryption to gorilla/securecookie’s CodecsFromPairs, encoding Session.Values directly into the cookie; FilesystemStore instead encodes only a random session.ID into the cookie and persists the actual Values to a file under a package-level sync.RWMutex (fileMutex) guarding concurrent reads/writes, with save/load/erase as small private helpers in store.go. Options (options.go) is a plain struct mirrored onto http.Cookie by newCookieFromOptions (cookie.go), and lex.go contributes a single isCookieNameValid helper adapted from Go’s standard library. Because Store is only three methods, swapping the persistence layer requires no changes to Session, Registry, or handler code — the abstraction boundary is deliberately narrow and stable.

Tech Stack gorilla/sessions is pure Go (module github.com/gorilla/sessions, go 1.23) with a single external dependency, github.com/gorilla/securecookie, which supplies the HMAC signing and optional AES encryption codecs used by both stores. It has no web framework dependency — it operates directly on net/http.Request and http.ResponseWriter, so it works unmodified with net/http or any router built on it. Session values are serialized with the standard library’s encoding/gob (registered via gob.Register in an init() function), so any custom type stored in Values must itself be gob-registered. Build tooling is a plain Makefile driving race-enabled tests, golangci-lint, gosec, and govulncheck; there is no ORM, database driver, or bundler — deployment is simply importing the package into a Go binary.

Code Quality Tests exist for all core source files with matching test counterparts, and CI runs them with race detection and coverage across Linux, macOS, and Windows on every push, uploading coverage to Codecov. Separate workflows run golangci-lint, gosec, and govulncheck on every push and pull request — an unusually thorough setup for a package this size. Error handling is explicit and idiomatic: store methods return errors and callers are shown checking them throughout the documentation; a MultiError type aggregates per-session save failures so a multi-session failure doesn’t mask individual errors. Naming is conventional exported-Go style with doc comments on every exported symbol. The main type-safety gap is inherent to the design rather than an oversight: session values are stored in a generic map requiring type assertions at every read site, and the maintainers themselves label the filesystem store as still experimental.

What Makes It Unique gorilla/sessions doesn’t introduce novel session-storage techniques — cookie signing and pluggable backend interfaces are well-established patterns predating this package. Its distinguishing choice is minimalism: a small Store interface that the community has independently implemented for over twenty backend adapters without needing changes to this package, and a registry mechanism for coordinating multiple simultaneous sessions per request that’s more ergonomic than most competing libraries’ single-session APIs. Built-in key-pair rotation is a small but genuinely useful operational feature that many hand-rolled cookie-session implementations omit. Overall this is standard, well-executed engineering rather than innovation.

Used by 8 apps in this directory

Python
55%
Other

authentik

Authentication · Security

25,245

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
67
Dependency
Built with
Python55%
TypeScript34%
Updated today
Go
51%
MIT

Fathom Lite

Analytics

8,013

A simple, self-hosted website analytics tool built with Go and Preact that lets you understand your traffic without handing data to third parties.

View details
48
Repo Health
67
Technical
68
Dependency
Built with
Go51%
JavaScript31%
CSS15%
Updated 5 months ago
Go
83%
MIT

Gitea

Devops · Developer Tools · Project Management

57,677

Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
Go83%
Updated today
Go
84%
MIT

Hatchet

AI Development · Developer Tools · Automation

7,812

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
68
Dependency
Built with
Go84%
PLpgSQL11%
Updated today
Go
91%
Apache 2.0

Ory Kratos

Authentication

13,853

API-first identity and user management that handles login, registration, MFA, and recovery so your application never has to.

View details
84
Repo Health
78
Technical
67
Dependency
Built with
Go91%
Updated 1 months ago
Go
39%
Apache 2.0

Rill

Analytics · Data Engineering

2,853

The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.

View details
87
Repo Health
88
Technical
66
Dependency
Built with
Go39%
TypeScript37%
Svelte22%
Updated 2 days ago
Go
79%
MIT

seonaut

Marketing · Developer Tools

776

Self-hosted SEO auditing that crawls your entire website and surfaces critical issues — broken links, duplicate meta tags, redirect loops, and more — before they hurt your rankings.

View details
43
Repo Health
77
Technical
68
Dependency
Built with
Go79%
HTML17%
Updated 3 months ago
Go
78%
MIT

Wakapi

Developer Tools · Analytics

4,413

Self-hosted WakaTime-compatible coding statistics backend that gives developers full control over their coding activity data.

View details
89
Repo Health
77
Technical
73
Dependency
Built with
Go78%
HTML12%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search