Commit 5abd327d authored by Rick Arnold's avatar Rick Arnold Committed by Brad Fitzpatrick

expvar: document that Get returns nil for non-existent vars

Also added a test to ensure the behavior.

Fixes #14150

Change-Id: Ib3ee9fdae59826fa594ce1be3c49b51d740b56eb
Reviewed-on: https://go-review.googlesource.com/19915Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 4accfe1b
......@@ -258,7 +258,8 @@ func Publish(name string, v Var) {
sort.Strings(varKeys)
}
// Get retrieves a named exported variable.
// Get retrieves a named exported variable. It returns nil if the name has
// not been registered.
func Get(name string) Var {
mutex.RLock()
defer mutex.RUnlock()
......
......@@ -26,6 +26,14 @@ func RemoveAll() {
varKeys = nil
}
func TestNil(t *testing.T) {
RemoveAll()
val := Get("missing")
if val != nil {
t.Errorf("got %v, want nil", val)
}
}
func TestInt(t *testing.T) {
RemoveAll()
reqs := NewInt("requests")
......
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