Helper functions to extract values from interface{} maps safely getString safely extracts a string value from a map[string]interface{}. This function handles the common pattern of extracting string values from JSON-decoded maps where the value type is interface{}. It performs safe type assertion an
(data map[string]interface{}, key string)
| 22 | // |
| 23 | // Returns the string value or empty string if not found or wrong type. |
| 24 | func getString(data map[string]interface{}, key string) string { |
| 25 | if val, ok := data[key]; ok { |
| 26 | if str, ok := val.(string); ok { |
| 27 | return str |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | return "" |
| 32 | } |
| 33 | |
| 34 | // getFloat safely extracts a numeric value from a map[string]interface{} as float64. |
| 35 | // |
no outgoing calls
no test coverage detected