Go expvar: publish public variables as JSON over HTTP
Answer: Package expvar provides a standardized interface to public variables, such as operation counters in servers.
Built-in variables and import
The package also registers cmdline from os.Args and memstats from runtime.
The package is sometimes only imported for the side effect of registering its HTTP handler.
Publish is how you add a named Var.
How they are exposed
It exposes these variables via HTTP at /debug/vars in JSON format.
The HTTP handler serves that JSON at /debug/vars.
As of Go 1.22, the /debug/vars request must use GET.
Helper constructors exist for Int, Float, String, and Map.
Operations to set or modify these public variables are atomic.
See also
Claims
- id: C1 claim: The package provides a standardized interface to public variables. source: S1 evidence: "Package expvar provides a standardized interface to public variables"
- id: C2 claim: Those variables are exposed at a debug HTTP path in JSON format. source: S1 evidence: "exposes these variables via HTTP at /debug/vars in JSON format"
- id: C3 claim: Operations that set or modify these public variables are atomic. source: S1 evidence: "Operations to set or modify these public variables are atomic"
- id: C4 claim: The package describes public variables such as operation counters in servers. source: S2 evidence: "as operation counters in servers"
Sources
- [S1] expvar package reference. Go. https://pkg.go.dev/expvar . License: BSD-3-Clause. Accessed 2026-11-24.
- [S2] expvar source. Go. https://go.dev/src/expvar/expvar.go . License: BSD-3-Clause. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, expvar package reference; Go, expvar source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, expvar package reference; Go, expvar source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go expvar: publish public variables as JSON over HTTP." iinventedlight Library, iil:note:e5rybbev, version of 2026-11-24. https://iinventedlight.com/library/notes/go-expvar/. License: CC-BY-4.0.
@misc{iil_note_e5rybbev,
author = {{iinventedlight}},
title = {{Go expvar: publish public variables as JSON over HTTP}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/go-expvar/},
note = {Permanent ID iil:note:e5rybbev. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-expvar.schema.json (schema; CC-BY-4.0)
- go-expvar.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-expvar.md.