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:
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
func
¶
- func Do(f func())
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() http.
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 )
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
- 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) *
func (*Float) Add
- func (v *Float) Add(delta )
Add adds delta to v.
func (*Float) Set
- func (v *Float) Set(value )
Set sets v to value.
func (*Float) String
- func (v *Float) String()
func (*Float) Value
- func (v *Float) Value()
type Func
- type Func func() interface{}
Func implements Var by calling the function and formatting the returned value
using JSON.
func (Func) String
func (Func) Value
- func (f Func) Value() interface{}
- type Int struct {
- // contains filtered or unexported fields
- }
Int is a 64-bit integer variable that satisfies the Var interface.
- func NewInt(name ) *Int
func (*Int)
¶
- func (v *) Add(delta int64)
func (*Int)
¶
func (*Int)
¶
- func (v *) String() string
func (*Int)
¶
- func (v *) Value() int64
type
¶
- type KeyValue struct {
- Key
- Value Var
- }
KeyValue represents a single entry in a Map.
type
¶
- type Map struct {
- // contains filtered or unexported fields
- }
Map is a string-to-Var map variable that satisfies the Var interface.
func
¶
- func NewMap(name ) *Map
func (*Map)
¶
- func (v *) Add(key string, delta )
Add adds delta to the *Int value stored under the given map key.
func (*Map) AddFloat
AddFloat adds delta to the *Float value stored under the given map key.
- func (v *Map) Do(f func())
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 (*Map)
¶
- func (v *) Init() *Map
Init removes all keys from the map.
func (*Map)
¶
- func (v *) Set(key string, av )
func (*Map) String
- func (v *Map) 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) *
func (*String) Set
- func (v *String) Set(value )
func (*String) String
- func (v *String) String()
String implements the Val interface. To get the unquoted string use Value.
- func (v *String) Value()
- 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 retrieves a named exported variable. It returns nil if the name has not been
registered.