W3cubDocs

/Go

Package 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:

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

Package files

expvar.go

func DoSource

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 HandlerSource

func Handler() http.Handler

Handler returns the expvar HTTP Handler.

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

func PublishSource

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 FloatSource

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

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

func NewFloatSource

func NewFloat(name string) *Float

func (*Float) AddSource

func (v *Float) Add(delta float64)

Add adds delta to v.

func (*Float) SetSource

func (v *Float) Set(value float64)

Set sets v to value.

func (*Float) StringSource

func (v *Float) String() string

func (*Float) ValueSource

func (v *Float) Value() float64

type FuncSource

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

type Func func() interface{}

func (Func) StringSource

func (f Func) String() string

func (Func) ValueSource

func (f Func) Value() interface{}

type IntSource

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

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

func NewIntSource

func NewInt(name string) *Int

func (*Int) AddSource

func (v *Int) Add(delta int64)

func (*Int) SetSource

func (v *Int) Set(value int64)

func (*Int) StringSource

func (v *Int) String() string

func (*Int) ValueSource

func (v *Int) Value() int64

type KeyValueSource

KeyValue represents a single entry in a Map.

type KeyValue struct {
        Key   string
        Value Var
}

type MapSource

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

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

func NewMapSource

func NewMap(name string) *Map

func (*Map) AddSource

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

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

func (*Map) AddFloatSource

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

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

func (*Map) DoSource

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) GetSource

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

func (*Map) InitSource

func (v *Map) Init() *Map

Init removes all keys from the map.

func (*Map) SetSource

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

func (*Map) StringSource

func (v *Map) String() string

type StringSource

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

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

func NewStringSource

func NewString(name string) *String

func (*String) SetSource

func (v *String) Set(value string)

func (*String) StringSource

func (v *String) String() string

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

func (*String) ValueSource

func (v *String) Value() string

type VarSource

Var is an abstract type for all exported variables.

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
}

func GetSource

func Get(name string) Var

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

© Google, Inc.
Licensed under the Creative Commons Attribution License 3.0.
https://golang.org/pkg/expvar/