Float64Map returns the map[string]float64 value of a given key path or an empty map[string]float64 if the path does not exist or if the value is not a valid float64 map.
(path string)
| 275 | // or an empty map[string]float64 if the path does not exist or if the |
| 276 | // value is not a valid float64 map. |
| 277 | func (ko *Koanf) Float64Map(path string) map[string]float64 { |
| 278 | var ( |
| 279 | out = map[string]float64{} |
| 280 | o = ko.Get(path) |
| 281 | ) |
| 282 | if o == nil { |
| 283 | return out |
| 284 | } |
| 285 | |
| 286 | mp, ok := o.(map[string]any) |
| 287 | if !ok { |
| 288 | return out |
| 289 | } |
| 290 | |
| 291 | out = make(map[string]float64, len(mp)) |
| 292 | for k, v := range mp { |
| 293 | switch i := v.(type) { |
| 294 | case float64: |
| 295 | out[k] = i |
| 296 | default: |
| 297 | // Attempt a conversion. |
| 298 | iv, err := toFloat64(i) |
| 299 | if err != nil { |
| 300 | return map[string]float64{} |
| 301 | } |
| 302 | out[k] = iv |
| 303 | } |
| 304 | } |
| 305 | return out |
| 306 | } |
| 307 | |
| 308 | // MustFloat64Map returns the map[string]float64 value of a given key path or panics |
| 309 | // if the value is not set or set to default value. |