initial commit

This commit is contained in:
2025-10-17 09:29:37 +03:00
commit 9739ede62e
25 changed files with 2270 additions and 0 deletions

58
internal/utils/utils.go Normal file
View File

@@ -0,0 +1,58 @@
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
}