expvar

package standard library
go1.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: BSD-3-Clause Imports: 12 Imported by: 16,372

Documentation ยถ

Overview ยถ

Package expvar provides a standardized interface to public variables, such as operation counters in servers. It exposes these variables via HTTP at /debug/vars in JSON format. As of Go 1.22, the /debug/vars request must use GET.

Operations to set or modify these public variables are atomic.

In addition to adding the HTTP handler, this package registers the following variables:

cmdline   os.Args
memstats  runtime.Memstats

The package is sometimes only imported for the side effect of registering its HTTP handler and the above variables. To use it this way, link this package into your program:

import _ "expvar"

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

This section is empty.

Functions ยถ

func Do ยถ

func Do(f func(KeyValue))

Do calls f for each exported variable. The global variable map is locked during the iteration, but existing entries may be concurrently updated.

func Handler ยถ added in go1.8

func Handler() http.Handler

Handler returns the expvar HTTP Handler.

This is only needed to install the handler in a non-standard location.

func Publish ยถ

func Publish(name string, v Var)

Publish declares a named exported variable. This should be called from a package's init function when it creates its Vars. If the name is already registered then this will log.Panic.

Types ยถ

type Float ยถ

type Float struct {
	// contains filtered or unexported fields
}

Float is a 64-bit float variable that satisfies the Var interface.

func NewFloat ยถ

func NewFloat(name string) *Float

func (*Float) Add ยถ

func (v *Float) Add(delta float64)

Add adds delta to v.

func (*Float) Set ยถ

func (v *Float) Set(value float64)

Set sets v to value.

func (*Float) String ยถ

func (v *Float) String() string

func (*Float) Value ยถ added in go1.8

func (v *Float) Value() float64

type Func ยถ

type Func func() any

Func implements Var by calling the function and formatting the returned value using JSON.

func (Func) String ยถ

func (f Func) String() string

func (Func) Value ยถ added in go1.8

func (f Func) Value() any

type Int ยถ

type Int struct {
	// contains filtered or unexported fields
}

Int is a 64-bit integer variable that satisfies the Var interface.

func NewInt ยถ

func NewInt(name string) *Int

func (*Int) Add ยถ

func (v *Int) Add(delta int64)

func (*Int) Set ยถ

func (v *Int) Set(value int64)

func (*Int) String ยถ

func (v *Int) String() string

func (*Int) Value ยถ added in go1.8

func (v *Int) Value() int64

type KeyValue ยถ

type KeyValue struct {
	Key   string
	Value Var
}

KeyValue represents a single entry in a Map.

type Map ยถ

type Map struct {
	// contains filtered or unexported fields
}

Map is a string-to-Var map variable that satisfies the Var interface.

func NewMap ยถ

func NewMap(name string) *Map

func (*Map) Add ยถ

func (v *Map) Add(key string, delta int64)

Add adds delta to the *Int value stored under the given map key.

func (*Map) AddFloat ยถ

func (v *Map) AddFloat(key string, delta float64)

AddFloat adds delta to the *Float value stored under the given map key.

func (*Map) Delete ยถ added in go1.12

func (v *Map) Delete(key string)

Delete deletes the given key from the map.

func (*Map) Do ยถ

func (v *Map) Do(f func(KeyValue))

Do calls f for each entry in the map. The map is locked during the iteration, but existing entries may be concurrently updated.

func (*Map) Get ยถ

func (v *Map) Get(key string) Var

func (*Map) Init ยถ

func (v *Map) Init() *Map

Init removes all keys from the map.

func (*Map) Set ยถ

func (v *Map) Set(key string, av Var)

func (*Map) String ยถ

func (v *Map) String() string

type String ยถ

type String struct {
	// contains filtered or unexported fields
}

String is a string variable, and satisfies the Var interface.

func NewString ยถ

func NewString(name string) *String

func (*String) Set ยถ

func (v *String) Set(value string)

func (*String) String ยถ

func (v *String) String() string

String implements the Var interface. To get the unquoted string use String.Value.

func (*String) Value ยถ added in go1.8

func (v *String) Value() string

type Var ยถ

type Var interface {
	// String returns a valid JSON value for the variable.
	// Types with String methods that do not return valid JSON
	// (such as time.Time) must not be used as a Var.
	String() string
}

Var is an abstract type for all exported variables.

func Get ยถ

func Get(name string) Var

Get retrieves a named exported variable. It returns nil if the name has not been registered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL