59 lines
748 B
Go
59 lines
748 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func ParseKB(s string) float64 {
|
|
s = strings.TrimSpace(strings.TrimSuffix(s, "kB"))
|
|
n, _ := strconv.ParseFloat(s, 64)
|
|
return n
|
|
}
|
|
|
|
func IntFrom(v any) int {
|
|
switch val := v.(type) {
|
|
case float64:
|
|
return int(val)
|
|
case int:
|
|
return val
|
|
default:
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func StrFrom(v any) string {
|
|
if s, ok := v.(string); ok {
|
|
return s
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func BoolToFloat(b bool) float64 {
|
|
if b {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func FloatFrom(v any) float64 {
|
|
switch val := v.(type) {
|
|
case float64:
|
|
return val
|
|
case int:
|
|
return float64(val)
|
|
default:
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func KbToInt(v any) int {
|
|
if s, ok := v.(string); ok {
|
|
var i int
|
|
fmt.Sscanf(s, "%d", &i)
|
|
return i
|
|
}
|
|
return 0
|
|
}
|