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:
parent
0f17db74ca
commit
5ce5baa748
1 changed files with 8 additions and 1 deletions
|
|
@ -9,8 +9,15 @@ func getString(data map[string]interface{}, key string) string {
|
|||
}
|
||||
|
||||
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
|
||||
case int64:
|
||||
return v != 0
|
||||
case int:
|
||||
return v != 0
|
||||
case float64:
|
||||
return v != 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue