MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / getFloat

Function getFloat

pkg/api/utils.go:45–66  ·  view source on GitHub ↗

getFloat safely extracts a numeric value from a map[string]interface{} as float64. This function handles multiple numeric types that can appear in JSON-decoded data, including float64, int, int64, and numeric strings. It performs safe type assertions and conversions. Parameters: - data: The map to

(data map[string]interface{}, key string)

Source from the content-addressed store, hash-verified

43//
44// Returns the numeric value as float64, or 0 if not found or not convertible.
45func getFloat(data map[string]interface{}, key string) float64 {
46 if val, ok := data[key]; ok {
47 switch v := val.(type) {
48 case float64:
49 if isFiniteFloat(v) {
50 return v
51 }
52 case int:
53 return float64(v)
54 case int64:
55 return float64(v)
56 case string:
57 // Try to convert string to float
58 var f float64
59 if n, err := fmt.Sscanf(v, "%f", &f); err == nil && n > 0 && isFiniteFloat(f) {
60 return f
61 }
62 }
63 }
64
65 return 0
66}
67
68// getBool safely extracts a boolean value from a map[string]interface{}.
69//

Callers 8

GetStorageContentMethod · 0.85
GetNodeStatusMethod · 0.85
GetNodeStoragesMethod · 0.85
GetNodeDisksMethod · 0.85
GetNodeDiskSmartMethod · 0.85
GetBackupsMethod · 0.85

Calls 1

isFiniteFloatFunction · 0.85

Tested by 1