github.com/blend/go-sdk@v1.20220411.3/expvar/func.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package expvar 9 10 import "encoding/json" 11 12 // Assert that `Func` implements `Var`. 13 var ( 14 _ Var = (*Func)(nil) 15 ) 16 17 // Func implements Var by calling the function 18 // and formatting the returned value using JSON. 19 type Func func() interface{} 20 21 // Value yields the result of calling the function. 22 func (f Func) Value() interface{} { 23 return f() 24 } 25 26 // String implements `Var`. 27 func (f Func) String() string { 28 v, _ := json.Marshal(f()) 29 return string(v) 30 }