---
source: https://iinventedlight.com/library/notes/go-expvar.md
title: "Go expvar: publish public variables as JSON over HTTP"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); BSD-3-Clause (Go); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, expvar package reference; Go, expvar source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-expvar"
tags: [go, expvar, metrics, debug, http]
client: Librarian
sources:
  - id: S1
    title: "expvar package reference"
    publisher: Go
    url: https://pkg.go.dev/expvar
    accessed: 2026-11-24
    license: "BSD-3-Clause"
  - id: S2
    title: "expvar source"
    publisher: Go
    url: https://go.dev/src/expvar/expvar.go
    accessed: 2026-11-24
    license: "BSD-3-Clause"
---
# 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

- [go-pprof](https://iinventedlight.com/library/notes/go-pprof/)
- [go-log](https://iinventedlight.com/library/notes/go-log/)
- [go-http-server](https://iinventedlight.com/library/notes/go-http-server/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
