Enhance getBool function to support multiple data types

- Refactored the getBool function to handle boolean values as well as int64, int, and float64 types, returning true for non-zero values.
- Improved type safety and flexibility in data handling within the utility functions.
This commit is contained in:
Max 2025-11-08 14:58:14 +08:00
parent 0f17db74ca
commit 5ce5baa748

View file

@ -9,8 +9,15 @@ func getString(data map[string]interface{}, key string) string {
} }
func getBool(data map[string]interface{}, key string) bool { func getBool(data map[string]interface{}, key string) bool {
if v, ok := data[key].(bool); ok { switch v := data[key].(type) {
case bool:
return v return v
case int64:
return v != 0
case int:
return v != 0
case float64:
return v != 0
} }
return false return false
} }