Commit 3b9c9d21 authored by Sam Thorogood's avatar Sam Thorogood Committed by Russ Cox

expvar: add (*Int).Set

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/2336044
parent 1abd293d
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
// such as operation counters in servers. It exposes these variables via // such as operation counters in servers. It exposes these variables via
// HTTP at /debug/vars in JSON format. // 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 // In addition to adding the HTTP handler, this package registers the
// following variables: // following variables:
// //
...@@ -50,6 +52,12 @@ func (v *Int) Add(delta int64) { ...@@ -50,6 +52,12 @@ func (v *Int) Add(delta int64) {
v.i += delta 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. // Map is a string-to-Var map variable, and satisfies the Var interface.
type Map struct { type Map struct {
m map[string]Var m map[string]Var
......
...@@ -27,6 +27,11 @@ func TestInt(t *testing.T) { ...@@ -27,6 +27,11 @@ func TestInt(t *testing.T) {
if s := reqs.String(); s != "4" { if s := reqs.String(); s != "4" {
t.Errorf("reqs.String() = %q, want \"4\"", s) 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) { func TestString(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment