MCPcopy
hub / github.com/knadh/koanf / Float64Map

Method Float64Map

getters.go:277–306  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

275// or an empty map[string]float64 if the path does not exist or if the
276// value is not a valid float64 map.
277func (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.

Callers 3

MustFloat64MapMethod · 0.95
TestFSProviderFunction · 0.80
TestGetTypesFunction · 0.80

Calls 2

GetMethod · 0.95
toFloat64Function · 0.85

Tested by 2

TestFSProviderFunction · 0.64
TestGetTypesFunction · 0.64