handlers

A collection of composable HTTP middleware for Go's net/http — logging, compression, CORS, proxy headers, and panic recovery.

Library
Go
vv1.5.2
1,740stars
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 →
69/100Good
Architecture78
Code Quality82
Innovation80
Learning Curve35

gorilla/handlers is a lightweight collection of standalone HTTP middleware for Go’s net/http package, covering common concerns like access logging, gzip/deflate compression, CORS, method overriding, and proxy header handling. Each handler wraps an http.Handler and works with net/http directly, so it drops into any router or framework that speaks the standard library’s handler interface.

Part of the broader Gorilla web toolkit, the package favors small, independently usable pieces over a monolithic middleware stack — you import only the handlers you need. It has shipped since 2013 and is widely used as a dependency by other Go web libraries and applications needing production-grade request logging, compression, and CORS support without adopting a full framework.

What You Get

  • Apache Common and Combined Log Format request logging via LoggingHandler and CombinedLoggingHandler
  • Gzip/deflate response compression with CompressHandler and CompressHandlerLevel
  • A full CORS middleware with functional options for origins, methods, headers, and credentials
  • ProxyHeaders middleware that normalizes X-Forwarded-* and RFC7239 Forwarded headers into the request
  • RecoveryHandler for catching panics and returning a 500 instead of crashing the server
  • MethodHandler and HTTPMethodOverrideHandler for routing and overriding HTTP methods
  • CanonicalHost middleware for redirecting requests to a canonical domain
  • ContentTypeHandler for validating incoming Content-Type headers

Common Use Cases

  • Adding Apache-style access logs to a Go HTTP service without a full observability stack
  • Enabling gzip compression for JSON/HTML API responses to cut bandwidth
  • Exposing a public API safely by configuring explicit CORS origins, methods, and headers
  • Running a Go service behind nginx/HAProxy/ELB and needing the correct client IP/scheme from proxy headers
  • Preventing a single panicking handler from taking down the whole server in production
  • Supporting HTML forms and legacy clients that can’t send PUT/PATCH/DELETE by allowing method override

Under The Hood

Architecture The package is a flat, single-Go-package collection of independent middleware — handlers.go, compress.go, cors.go, proxy_headers.go, recovery.go, logging.go, and canonical.go — with no internal layering or shared state between them. Nearly every handler follows the same decorator pattern, either func(http.Handler) http.Handler or a small struct wrapping an http.Handler and implementing ServeHTTP itself, so any handler can be composed with any other by nesting function calls. The only cross-file dependency is a shared responseLogger/compressResponseWriter pattern for intercepting Write/WriteHeader calls, and an external httpsnoop dependency is used to preserve optional interfaces like http.Hijacker and http.Flusher when wrapping the ResponseWriter. Removing or replacing any single handler has no effect on the others, which is the intended design.

Tech Stack The module targets Go 1.20 and depends on the standard library almost exclusively (net/http, compress/gzip, compress/flate, regexp), with a single third-party dependency, github.com/felixge/httpsnoop v1.0.3, used to wrap http.ResponseWriter without losing optional interface support. There is no build tooling beyond go build/go test; a Makefile wires up golangci-lint, gosec, and govulncheck for local and CI verification, and GitHub Actions runs the test suite on push.

Code Quality Every source file has a matching _test.go counterpart (handlers_test.go, compress_test.go, cors_test.go, canonical_test.go, logging_test.go, proxy_headers_test.go, recovery_test.go), and CI runs tests with -race -cover. Error handling is mostly explicit — panics are recovered deliberately in RecoveryHandler and errors from write operations are checked — though a couple of //nolint markers flag known style debt around ignored type-assertion errors that the maintainers left as TODOs rather than silently swallowing. Exported identifiers carry full godoc comments, naming is idiomatic Go, and golangci-lint/gosec/govulncheck run in the verify pipeline.

API Design The consistent decorator signature (func(h http.Handler) http.Handler) means most handlers can be composed with zero configuration — just wrap the next handler in the chain — while the more configurable ones (CORS, RecoveryHandler) use the functional-options pattern (CORSOption, RecoveryOption) instead of large config structs, keeping call sites terse. Because everything operates on the standard http.Handler interface, the package integrates with any router (net/http’s ServeMux, gorilla/mux, chi, etc.) with no adapter code required, and the public API surface is small and has stayed stable across its decade of releases.

Used by 7 apps in this directory

Go
85%
Apache 2.0

Argo Workflows

Devops · Data Engineering

16,943

The most popular Kubernetes-native workflow engine for orchestrating containerized DAGs, ML pipelines, CI/CD, and parallel batch jobs at scale.

View details
95
Repo Health
90
Technical
68
Dependency
Built with
Go85%
TypeScript11%
Updated yesterday
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
TypeScript
51%
Other

Mattermost

Team Chat · Collaboration · Devops

38,940

Open core, self-hosted team collaboration with chat, AI agents, voice calling, and deep DevOps integrations — all under your control.

View details
96
Repo Health
87
Technical
65
Dependency
Built with
TypeScript51%
Go40%
Updated yesterday
Go
95%
Apache 2.0

Nakama

Developer Tools · Game Development

13,238

Open-source game backend server with built-in multiplayer, matchmaking, leaderboards, chat, authentication, and storage — deploy anywhere via Docker or binary.

View details
88
Repo Health
73
Technical
74
Dependency
Built with
Go95%
Updated 5 days ago
Go
96%
Other

Netmaker

Automation · Security

11,771

Automate secure WireGuard mesh networks from homelab to enterprise scale without manual configuration.

View details
92
Repo Health
79
Technical
71
Dependency
Built with
Go96%
Updated today
TypeScript
52%
Other

SigNoz

Monitoring · Analytics

31,972

Self-host your entire observability stack — logs, metrics, traces, and LLM monitoring — in one OpenTelemetry-native platform, without the Datadog bill.

View details
92
Repo Health
83
Technical
69
Dependency
Built with
TypeScript52%
Go37%
Updated today

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