| 15 | var k = koanf.New(".") |
| 16 | |
| 17 | func 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 | } |