mirror of
https://github.com/golang/go
synced 2024-11-17 22:14:43 -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:
parent
4accfe1be5
commit
5abd327d00
@ -258,7 +258,8 @@ func Publish(name string, v Var) {
|
|||||||
sort.Strings(varKeys)
|
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 {
|
func Get(name string) Var {
|
||||||
mutex.RLock()
|
mutex.RLock()
|
||||||
defer mutex.RUnlock()
|
defer mutex.RUnlock()
|
||||||
|
@ -26,6 +26,14 @@ func RemoveAll() {
|
|||||||
varKeys = nil
|
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) {
|
func TestInt(t *testing.T) {
|
||||||
RemoveAll()
|
RemoveAll()
|
||||||
reqs := NewInt("requests")
|
reqs := NewInt("requests")
|
||||||
|
Loading…
Reference in New Issue
Block a user