File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -16,14 +16,17 @@ package monkit
1616
1717import "reflect"
1818
19- var f64Type = reflect .TypeOf (float64 (0 ))
19+ var (
20+ f64Type = reflect .TypeOf (float64 (0 ))
21+ boolType = reflect .TypeOf (bool (false ))
22+ )
2023
2124type emptyStatSource struct {}
2225
2326func (emptyStatSource ) Stats (cb func (key SeriesKey , field string , val float64 )) {}
2427
2528// StatSourceFromStruct uses the reflect package to implement the Stats call
26- // across all float64-castable fields of the struct.
29+ // across all float64-castable and bool-castable fields of the struct.
2730func StatSourceFromStruct (key SeriesKey , structData interface {}) StatSource {
2831 val := deref (reflect .ValueOf (structData ))
2932
@@ -45,6 +48,12 @@ func StatSourceFromStruct(key SeriesKey, structData interface{}) StatSource {
4548
4649 } else if field_type .ConvertibleTo (f64Type ) {
4750 cb (key , typ .Field (i ).Name , field .Convert (f64Type ).Float ())
51+ } else if field_type .ConvertibleTo (boolType ) {
52+ if field .Convert (boolType ).Bool () {
53+ cb (key , typ .Field (i ).Name , 1 )
54+ } else {
55+ cb (key , typ .Field (i ).Name , 0 )
56+ }
4857 }
4958 }
5059 })
You can’t perform that action at this time.
0 commit comments