mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Add SetKeyDelimiter to the README
This commit is contained in:
parent
a73303ee89
commit
9a405be5c0
1 changed files with 27 additions and 0 deletions
27
README.md
27
README.md
|
@ -663,6 +663,33 @@ if err != nil {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to unmarshal configuration where the keys themselves contain dot (the default key delimiter),
|
||||||
|
you have to change the delimiter:
|
||||||
|
|
||||||
|
```go
|
||||||
|
v := viper.New()
|
||||||
|
v.SetKeyDelimiter("::")
|
||||||
|
|
||||||
|
v.SetDefault("chart::values", map[string]interface{}{
|
||||||
|
"ingress": map[string]interface{}{
|
||||||
|
"annotations": map[string]interface{}{
|
||||||
|
"traefik.frontend.rule.type": "PathPrefix",
|
||||||
|
"traefik.ingress.kubernetes.io/ssl-redirect": "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
Chart struct{
|
||||||
|
Values map[string]interface{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var C config
|
||||||
|
|
||||||
|
viper.Unmarshal(&C)
|
||||||
|
```
|
||||||
|
|
||||||
Viper uses [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) under the hood for unmarshaling values which uses `mapstructure` tags by default.
|
Viper uses [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) under the hood for unmarshaling values which uses `mapstructure` tags by default.
|
||||||
|
|
||||||
### Marshalling to string
|
### Marshalling to string
|
||||||
|
|
Loading…
Reference in a new issue