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

Function main

examples/default-values/main.go:17–36  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15var k = koanf.New(".")
16
17func main() {
18 // Load default values using the confmap provider.
19 // We provide a flat map with the "." delimiter.
20 // A nested map can be loaded by setting the delimiter to an empty string "".
21 k.Load(confmap.Provider(map[string]any{
22 "parent1.name": "Default Name",
23 "parent3.name": "New name here",
24 }, "."), nil)
25
26 // Load JSON config on top of the default values.
27 if err := k.Load(file.Provider("mock/mock.json"), json.Parser()); err != nil {
28 log.Fatalf("error loading config: %v", err)
29 }
30
31 // Load YAML config and merge into the previously loaded config (because we can).
32 k.Load(file.Provider("mock/mock.yml"), yaml.Parser())
33
34 fmt.Println("parent's name is = ", k.String("parent1.name"))
35 fmt.Println("parent's ID is = ", k.Int("parent1.id"))
36}

Callers

nothing calls this directly

Calls 3

LoadMethod · 0.80
StringMethod · 0.80
IntMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…