]> Cypherpunks repositories - gostls13.git/commitdiff
expvar: document that Get returns nil for non-existent vars
authorRick Arnold <rickarnoldjr@gmail.com>
Thu, 25 Feb 2016 00:25:38 +0000 (19:25 -0500)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 25 Feb 2016 16:48:08 +0000 (16:48 +0000)
Also added a test to ensure the behavior.

Fixes #14150

Change-Id: Ib3ee9fdae59826fa594ce1be3c49b51d740b56eb
Reviewed-on: https://go-review.googlesource.com/19915
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/expvar/expvar.go
src/expvar/expvar_test.go

index 24c2d6b29ab4221928104eb052ff693bb223f733..1d51bc97f9f5bf5ca6e5996c62f7dbe7943b9cda 100644 (file)
@@ -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()
index 8bc633e4a9767acd61bd28e6cd6578b3046eca70..385fea81adbba98fa8467a716b1c19e8dc933dd0 100644 (file)
@@ -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")