mirror of
https://github.com/hikhvar/mqtt2prometheus.git
synced 2026-02-14 09:59:52 +00:00
Merge pull request #161 from fatpat/expr_int/float
improve expr float() and int() to handle strings
This commit is contained in:
@@ -84,6 +84,12 @@ func toInt64(i interface{}) int64 {
|
||||
return v
|
||||
case time.Duration:
|
||||
return int64(v)
|
||||
case string:
|
||||
value, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return value
|
||||
default:
|
||||
return v.(int64) // Hope for the best
|
||||
}
|
||||
@@ -103,6 +109,12 @@ func toFloat64(i interface{}) float64 {
|
||||
return float64(v)
|
||||
case time.Duration:
|
||||
return float64(v)
|
||||
case string:
|
||||
value, err := strconv.ParseFloat(v, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return value
|
||||
default:
|
||||
return v.(float64) // Hope for the best
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user