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

Function getBool

pkg/api/utils.go:82–97  ·  view source on GitHub ↗

getBool safely extracts a boolean value from a map[string]interface{}. This function handles multiple representations of boolean values that can appear in JSON or form data: - bool: true/false - int: 0 (false) or non-zero (true) - float64: 0.0 (false) or non-zero (true) - string: "true", "1" (true)

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

Source from the content-addressed store, hash-verified

80//
81// Returns the boolean value or false if not found or not convertible.
82func getBool(data map[string]interface{}, key string) bool {
83 if val, ok := data[key]; ok {
84 switch v := val.(type) {
85 case bool:
86 return v
87 case int:
88 return v != 0
89 case float64:
90 return v != 0
91 case string:
92 return v == "1" || strings.EqualFold(v, "true")
93 }
94 }
95
96 return false
97}
98
99// getInt safely extracts an integer value from a map[string]interface{}.
100//

Callers 5

GetNodeStoragesMethod · 0.85
GetNodeDiskSmartMethod · 0.85
GetSnapshotsMethod · 0.85
getClusterBasicStatusMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected