← All notes

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

Sources

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

Permanent ID: iil:note:e5rybbev

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.},
}

Markdown

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.

All artifact files (JSON index)

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.