-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed as not planned
Labels
Description
Test code:
package main
import (
"bytes"
"fmt"
"github.com/spf13/viper"
)
type Config struct {
Foo struct {
Bar map[string]int `mapstructure:"bar"`
} `mapstructure:"foo"`
}
var content = []byte(`
foo:
bar:
"x": 1
"y": 2
"z.z": 3
`)
func main() {
var c1, c2 Config
viper.SetConfigType("yaml")
viper.ReadConfig(bytes.NewReader(content))
viper.Unmarshal(&c1)
fmt.Println("c1:", c1)
viper.UnmarshalKey("foo", &c2.Foo)
fmt.Println("c2:", c2)
}
Output:
c1: {{map[x:1 y:2]}}
c2: {{map[x:1 y:2 z.z:3]}}
As you can see, when the map key contains dot, UnmarshalKey works correctly but Unmarshal doesn't.
Reactions are currently unavailable