Skip to content

Commit 6bd07d1

Browse files
authored
Merge pull request #161 from fatpat/expr_int/float
improve expr float() and int() to handle strings
2 parents 3a9ad76 + e18dc0b commit 6bd07d1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/metrics/parser.go

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ func toInt64(i interface{}) int64 {
8484
return v
8585
case time.Duration:
8686
return int64(v)
87+
case string:
88+
value, err := strconv.ParseInt(v, 10, 64)
89+
if err != nil {
90+
panic(err)
91+
}
92+
return value
8793
default:
8894
return v.(int64) // Hope for the best
8995
}
@@ -103,6 +109,12 @@ func toFloat64(i interface{}) float64 {
103109
return float64(v)
104110
case time.Duration:
105111
return float64(v)
112+
case string:
113+
value, err := strconv.ParseFloat(v, 64)
114+
if err != nil {
115+
panic(err)
116+
}
117+
return value
106118
default:
107119
return v.(float64) // Hope for the best
108120
}

0 commit comments

Comments
 (0)