sessions

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

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

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
48 /100 Fair
Development Activity 0
Maintenance 20
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
72 /100 Good
Architecture 84
Code Quality 85
Innovation 55
Learning Curve 65

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 9 apps in this directory

Python
55%
Other

authentik

Authentication · Security

25,897

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
66
Dependency
Built with
Python 55%
TypeScript 35%
Updated today
Go
51%
MIT

Fathom Lite

Analytics

8,020

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
47
Repo Health
67
Technical
67
Dependency
Built with
Go 51%
JavaScript 31%
CSS 15%
Updated 6 months ago
Go
83%
MIT

Gitea

Developer Tools · Devops · Project Management

58,399

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
64
Dependency
Built with
Go 83%
Updated yesterday
Go
86%
MIT

Hatchet

AI Development · Automation · Developer Tools

8,091

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
67
Dependency
Built with
Go 86%
Updated yesterday
Go
91%
Apache 2.0

Ory Kratos

Authentication

13,913

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

View details
79
Repo Health
78
Technical
65
Dependency
Built with
Go 91%
Updated 2 months ago
Go
39%
Apache 2.0

Rill

Analytics · Data Engineering

2,936

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
88
Repo Health
88
Technical
64
Dependency
Built with
Go 39%
TypeScript 38%
Svelte 21%
Updated today
Go
79%
MIT

seonaut

Developer Tools · Marketing

805

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
58
Repo Health
77
Technical
67
Dependency
Built with
Go 79%
HTML 17%
Updated 2 days ago
Go
79%
MIT

Wakapi

Analytics · Developer Tools

4,448

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

View details
89
Repo Health
77
Technical
72
Dependency
Built with
Go 79%
HTML 12%
Updated 3 days ago
Go
66%
AGPL 3.0

WriteFreely

Blogging · Social Media

5,266

A clean, Markdown-based publishing platform for writers, with built-in ActivityPub federation for connecting to the wider fediverse.

View details
87
Repo Health
63
Technical
69
Dependency
Built with
Go 66%
Go Template 23%
Updated 1 weeks 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