From 9a405be5c05f793c04480d3137cf4880d147ccbe Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 6 Nov 2019 12:54:38 +0100 Subject: [PATCH] Add SetKeyDelimiter to the README --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index a6c9a3e..f211b06 100644 --- a/README.md +++ b/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. ### Marshalling to string