我想用 viper 加载以下配置:
artist:
name: The Beatles
albums:
- name: The White Album
year: 1968
- name: Abbey Road
year: 1969
我不知道如何加载地图列表。我想我只需要解组这个键,但是这段代码不起作用:
type Album struct {
Name string
Year int
}
type Artist struct {
Name string
Albums []Album
}
var artist Artist
viper.UnmarshalKey("artists", &artist)
我错过了什么?