expvar

Imports

Imports #

"encoding/json"
"internal/godebug"
"log"
"math"
"net/http"
"os"
"runtime"
"slices"
"strconv"
"sync"
"sync/atomic"
"unicode/utf8"

Constants & Variables

vars var #

All published variables.

var vars Map

Type Aliases

Func type #

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

type Func func() any

Interfaces

Var interface #

Var is an abstract type for all exported variables.

type Var interface {
String() string
}

jsonVar interface #

type jsonVar interface {
appendJSON(b []byte) []byte
}

Structs

Float struct #

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

type Float struct {
f atomic.Uint64
}

Int struct #

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

type Int struct {
i atomic.Int64
}

KeyValue struct #

KeyValue represents a single entry in a [Map].

type KeyValue struct {
Key string
Value Var
}

Map struct #

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

type Map struct {
m sync.Map
keysMu sync.RWMutex
keys []string
}

String struct #

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

type String struct {
s atomic.Value
}

Functions

Add method #

func (v *Int) Add(delta int64)

Add method #

Add adds delta to v.

func (v *Float) Add(delta float64)

Add method #

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

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

AddFloat method #

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

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

Delete method #

Delete deletes the given key from the map.

func (v *Map) Delete(key string)

Do function #

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

func Do(f func(KeyValue))

Do method #

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

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

Get function #

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

func Get(name string) Var

Get method #

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

Handler function #

Handler returns the expvar HTTP Handler. This is only needed to install the handler in a non-standard location.

func Handler() http.Handler

Init method #

Init removes all keys from the map.

func (v *Map) Init() *Map

NewFloat function #

func NewFloat(name string) *Float

NewInt function #

func NewInt(name string) *Int

NewMap function #

func NewMap(name string) *Map

NewString function #

func NewString(name string) *String

Publish function #

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.

func Publish(name string, v Var)

Set method #

func (v *String) Set(value string)

Set method #

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

Set method #

Set sets v to value.

func (v *Float) Set(value float64)

Set method #

func (v *Int) Set(value int64)

String method #

func (f Func) String() string

String method #

func (v *Float) String() string

String method #

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

func (v *String) String() string

String method #

func (v *Int) String() string

String method #

func (v *Map) String() string

Value method #

func (f Func) Value() any

Value method #

func (v *Int) Value() int64

Value method #

func (v *String) Value() string

Value method #

func (v *Float) Value() float64

addKey method #

addKey updates the sorted list of keys in v.keys.

func (v *Map) addKey(key string)

appendJSON method #

func (v *Map) appendJSON(b []byte) []byte

appendJSON method #

func (v *Float) appendJSON(b []byte) []byte

appendJSON method #

func (v *Int) appendJSON(b []byte) []byte

appendJSON method #

func (v *String) appendJSON(b []byte) []byte

appendJSONMayExpand method #

func (v *Map) appendJSONMayExpand(b []byte, expand bool) []byte

appendJSONQuote function #

TODO: Use json.appendString instead.

func appendJSONQuote(b []byte, s string) []byte

cmdline function #

func cmdline() any

expvarHandler function #

func expvarHandler(w http.ResponseWriter, r *http.Request)

init function #

func init()

memstats function #

func memstats() any

Generated with Arrow