1
0
mirror of https://github.com/golang/go synced 2024-11-17 20:44:47 -07:00

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/19915
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rick Arnold 2016-02-24 19:25:38 -05:00 committed by Brad Fitzpatrick
parent 4accfe1be5
commit 5abd327d00
2 changed files with 10 additions and 1 deletions

View 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()

View 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")