You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,8 +52,8 @@ go get -u github.com/knadh/koanf/parsers/toml
52
52
53
53
### Concepts
54
54
55
-
-`koanf.Provider` is a generic interface that provides configuration, for example, from files, environment variables, HTTP sources, or anywhere. The configuration can either be raw bytes that a parser can parse, or it can be a nested `map[string]interface{}` that can be directly loaded.
56
-
-`koanf.Parser` is a generic interface that takes raw bytes, parses, and returns a nested `map[string]interface{}`. For example, JSON and YAML parsers.
55
+
-`koanf.Provider` is a generic interface that provides configuration, for example, from files, environment variables, HTTP sources, or anywhere. The configuration can either be raw bytes that a parser can parse, or it can be a nested `map[string]any` that can be directly loaded.
56
+
-`koanf.Parser` is a generic interface that takes raw bytes, parses, and returns a nested `map[string]any`. For example, JSON and YAML parsers.
57
57
- Once loaded into koanf, configuration are values queried by a delimited key path syntax. eg: `app.server.port`. Any delimiter can be chosen.
58
58
- Configuration from multiple sources can be loaded and merged into a koanf instance, for example, load from a file first and override certain values with flags from the command line.
59
59
@@ -133,7 +133,7 @@ func main() {
133
133
// Watch the file and get a callback on change. The callback can do whatever,
134
134
// like re-load the configuration.
135
135
// File provider always returns a nil `event`.
136
-
f.Watch(func(event interface{}, err error) {
136
+
f.Watch(func(event any, err error) {
137
137
if err != nil {
138
138
log.Printf("watch error: %v", err)
139
139
return
@@ -430,7 +430,7 @@ func main() {
430
430
431
431
#### Reading from nested maps
432
432
433
-
The bundled `confmap` provider takes a `map[string]interface{}` that can be loaded into a koanf instance.
433
+
The bundled `confmap` provider takes a `map[string]any` that can be loaded into a koanf instance.
434
434
435
435
```go
436
436
package main
@@ -453,7 +453,7 @@ func main() {
453
453
// Load default values using the confmap provider.
454
454
// We provide a flat map with the "." delimiter.
455
455
// A nested map can be loaded by setting the delimiter to an empty string "".
456
-
k.Load(confmap.Provider(map[string]interface{}{
456
+
k.Load(confmap.Provider(map[string]any{
457
457
"parent1.name": "Default Name",
458
458
"parent3.name": "New name here",
459
459
}, "."), nil)
@@ -596,11 +596,11 @@ For example: merging JSON and YAML will most likely fail because JSON treats int
596
596
597
597
### Custom Providers and Parsers
598
598
599
-
A Provider returns a nested `map[string]interface{}` config that can be loaded directly into koanf with `koanf.Load()` or it can return raw bytes that can be parsed with a Parser (again, loaded using `koanf.Load()`. Writing Providers and Parsers are easy. See the bundled implementations in the [providers](https://github.com/knadh/koanf/tree/master/providers) and [parsers](https://github.com/knadh/koanf/tree/master/parsers) directories.
599
+
A Provider returns a nested `map[string]any` config that can be loaded directly into koanf with `koanf.Load()` or it can return raw bytes that can be parsed with a Parser (again, loaded using `koanf.Load()`. Writing Providers and Parsers are easy. See the bundled implementations in the [providers](https://github.com/knadh/koanf/tree/master/providers) and [parsers](https://github.com/knadh/koanf/tree/master/parsers) directories.
600
600
601
601
### Custom merge strategies
602
602
603
-
By default, when merging two config sources using `Load()`, koanf recursively merges keys of nested maps (`map[string]interface{}`),
603
+
By default, when merging two config sources using `Load()`, koanf recursively merges keys of nested maps (`map[string]any`),
604
604
while static values are overwritten (slices, strings, etc). This behaviour can be changed by providing a custom merge function with the `WithMergeFunc` option.
605
605
606
606
```go
@@ -630,7 +630,7 @@ func main() {
630
630
}
631
631
632
632
jsonPath := "mock/mock.json"
633
-
if err := k.Load(file.Provider(jsonPath), json.Parser(), koanf.WithMergeFunc(func(src, dest map[string]interface{}) error {
633
+
if err := k.Load(file.Provider(jsonPath), json.Parser(), koanf.WithMergeFunc(func(src, dest map[string]any) error {
634
634
// Your custom logic, copying values from src into dst
635
635
return nil
636
636
})); err != nil {
@@ -654,8 +654,8 @@ Install with `go get -u github.com/knadh/koanf/providers/$provider`
| posflag | `posflag.Provider(f *pflag.FlagSet, delim string)` | Takes an `spf13/pflag.FlagSet` (advanced POSIX compatible flags with multiple types) and provides a nested config map based on delim. |
656
656
| env/v2 | `env.Provider(prefix, delim string, f func(s string) string)` | Takes an optional prefix to filter env variables by, an optional function that takes and returns a string to transform env variables, and returns a nested config map based on delim. |
657
-
| confmap | `confmap.Provider(mp map[string]interface{}, delim string)` | Takes a premade `map[string]interface{}` conf map. If delim is provided, the keys are assumed to be flattened, thus unflattened using delim. |
658
-
| structs | `structs.Provider(s interface{}, tag string)` | Takes a struct and struct tag. |
657
+
| confmap | `confmap.Provider(mp map[string]any, delim string)` | Takes a premade `map[string]any` conf map. If delim is provided, the keys are assumed to be flattened, thus unflattened using delim. |
658
+
| structs | `structs.Provider(s any, tag string)` | Takes a struct and struct tag. |
0 commit comments