version: 1.10

package expvar

import "expvar"

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.

Operations to set or modify these public variables are atomic.

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

  1. cmdline os.Args
  2. 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:

  1. import _ "expvar"

Index

Package files

expvar.go

func Do

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

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

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

type Float

  1. type Float struct {
  2. // contains filtered or unexported fields
  3. }

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

func NewFloat

  1. func NewFloat(name string) *Float

func (*Float) Add

  1. func (v *Float) Add(delta float64)

Add adds delta to v.

func (*Float) Set

  1. func (v *Float) Set(value float64)

Set sets v to value.

func (*Float) String

  1. func (v *Float) String() string

func (*Float) Value

  1. func (v *Float) Value() float64

type Func

  1. type Func func() interface{}

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

func (Func) String

  1. func (f Func) String() string

func (Func) Value

  1. func (f Func) Value() interface{}

type Int

  1. type Int struct {
  2. // contains filtered or unexported fields
  3. }

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

func NewInt

  1. func NewInt(name string) *Int

func (*Int) Add

  1. func (v *Int) Add(delta int64)

func (*Int) Set

  1. func (v *Int) Set(value int64)

func (*Int) String

  1. func (v *Int) String() string

func (*Int) Value

  1. func (v *Int) Value() int64

type KeyValue

  1. type KeyValue struct {
  2. Key string
  3. Value Var
  4. }

KeyValue represents a single entry in a Map.

type Map

  1. type Map struct {
  2. // contains filtered or unexported fields
  3. }

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

func NewMap

  1. func NewMap(name string) *Map

func (*Map) Add

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

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

func (*Map) AddFloat

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

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

func (*Map) Do

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

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

func (*Map) Init

  1. func (v *Map) Init() *Map

Init removes all keys from the map.

func (*Map) Set

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

func (*Map) String

  1. func (v *Map) String() string

type String

  1. type String struct {
  2. // contains filtered or unexported fields
  3. }

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

func NewString

  1. func NewString(name string) *String

func (*String) Set

  1. func (v *String) Set(value string)

func (*String) String

  1. func (v *String) String() string

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

func (*String) Value

  1. func (v *String) Value() string

type Var

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

Var is an abstract type for all exported variables.

func Get

  1. func Get(name string) Var

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