diff options
Diffstat (limited to 'libgo/go/expvar/expvar.go')
-rw-r--r-- | libgo/go/expvar/expvar.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/libgo/go/expvar/expvar.go b/libgo/go/expvar/expvar.go index 24c2d6b29ab..d5465c518f8 100644 --- a/libgo/go/expvar/expvar.go +++ b/libgo/go/expvar/expvar.go @@ -15,7 +15,7 @@ // memstats runtime.Memstats // // The package is sometimes only imported for the side effect of -// registering its HTTP handler and the above variables. To use it +// registering its HTTP handler and the above variables. To use it // this way, link this package into your program: // import _ "expvar" // @@ -38,6 +38,9 @@ import ( // Var is an abstract type for all exported variables. type Var interface { + // String returns a valid JSON value for the variable. + // Types with String methods that do not return valid JSON + // (such as time.Time) must not be used as a Var. String() string } @@ -218,8 +221,10 @@ type String struct { func (v *String) String() string { v.mu.RLock() - defer v.mu.RUnlock() - return strconv.Quote(v.s) + s := v.s + v.mu.RUnlock() + b, _ := json.Marshal(s) + return string(b) } func (v *String) Set(value string) { @@ -258,7 +263,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() |