1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:44:44 -07:00

expvar: add (*Int).Set

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/2336044
This commit is contained in:
Sam Thorogood 2010-10-11 13:14:07 -04:00 committed by Russ Cox
parent 1abd293d01
commit 3b9c9d2125
2 changed files with 13 additions and 0 deletions

View File

@ -6,6 +6,8 @@
// 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:
//
@ -50,6 +52,12 @@ func (v *Int) Add(delta int64) {
v.i += delta
}
func (v *Int) Set(value int64) {
v.mu.Lock()
defer v.mu.Unlock()
v.i = value
}
// Map is a string-to-Var map variable, and satisfies the Var interface.
type Map struct {
m map[string]Var

View File

@ -27,6 +27,11 @@ func TestInt(t *testing.T) {
if s := reqs.String(); s != "4" {
t.Errorf("reqs.String() = %q, want \"4\"", s)
}
reqs.Set(-2)
if reqs.i != -2 {
t.Errorf("reqs.i = %v, want -2", reqs.i)
}
}
func TestString(t *testing.T) {