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

Method Get

koanf.go:329–368  ·  view source on GitHub ↗

Get returns the raw, uncast any value of a given key path in the config map. If the key path does not exist, nil is returned.

(path string)

Source from the content-addressed store, hash-verified

327// Get returns the raw, uncast any value of a given key path
328// in the config map. If the key path does not exist, nil is returned.
329func (ko *Koanf) Get(path string) any {
330 // No path. Return the whole conf map.
331 if path == "" {
332 return ko.Raw()
333 }
334
335 // Does the path exist?
336 ko.mu.RLock()
337 defer ko.mu.RUnlock()
338
339 p, ok := ko.keyMap[path]
340 if !ok {
341 return nil
342 }
343 res := maps.Search(ko.confMap, p)
344
345 // Non-reference types are okay to return directly.
346 // Other types are "copied" with maps.Copy or json.Marshal
347 // that change the numeric types to float64.
348
349 switch v := res.(type) {
350 case int, int8, int16, int32, int64, float32, float64, string, bool:
351 return v
352 case map[string]any:
353 return maps.Copy(v)
354 case nil:
355 return nil
356 }
357
358 // Skip nil pointers before copying.
359 if rv := reflect.ValueOf(res); rv.Kind() == reflect.Ptr && rv.IsNil() {
360 return res
361 }
362
363 out, _ := copystructure.Copy(&res)
364 if ptrOut, ok := out.(*any); ok {
365 return *ptrOut
366 }
367 return out
368}
369
370// Slices returns a list of Koanf instances constructed out of a
371// []map[string]any interface at the given path.

Callers 15

CutMethod · 0.95
UnmarshalWithConfMethod · 0.95
SlicesMethod · 0.95
MapKeysMethod · 0.95
Int64Method · 0.95
Int64sMethod · 0.95
Int64MapMethod · 0.95
IntsMethod · 0.95
Float64Method · 0.95
Float64sMethod · 0.95
Float64MapMethod · 0.95
StringMethod · 0.95

Calls 2

RawMethod · 0.95
CopyMethod · 0.80

Tested by 8

TestNatsFunction · 0.64
TestFSProviderFunction · 0.64
TestMergeAtFunction · 0.64
TestSetFunction · 0.64
TestGetExistsFunction · 0.64
TestGetTypesFunction · 0.64
TestNoDeadlockFunction · 0.64
TestGetNilPointerFunction · 0.64