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

Function getInt

pkg/api/utils.go:110–126  ·  view source on GitHub ↗

getInt safely extracts an integer value from a map[string]interface{}. This function handles multiple numeric types that can appear in JSON-decoded data, including int, float64, and numeric strings. It performs safe type assertions and conversions, truncating floating-point values to integers. Par

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

Source from the content-addressed store, hash-verified

108//
109// Returns the integer value or 0 if not found or not convertible.
110func getInt(data map[string]interface{}, key string) int {
111 if val, ok := data[key]; ok {
112 switch v := val.(type) {
113 case int:
114 return v
115 case float64:
116 return int(v)
117 case string:
118 var i int
119 if _, err := fmt.Sscanf(v, "%d", &i); err == nil {
120 return i
121 }
122 }
123 }
124
125 return 0
126}
127
128// FormatBytes converts a byte count into a human-readable string with appropriate units.
129//

Callers 4

GetStorageContentMethod · 0.85
GetNextIDMethod · 0.85
getClusterBasicStatusMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected