我正在尝试迭代 golang 中的接口映射,它具有以下结构,我可以使用 for 循环迭代到单个级别,但无法深入获取接口的值。
yaml
steps:
execute:
- mvn : 1.9.3
goals: 'clean install'
concurrent: false
- mvn : 1.9.3
goals: 'dependency-check:check'
concurrent: false
去
// reading a yaml file
// trying to use "gopkg.in/yaml.v2" package
data, err := ioutil.ReadFile(fileName)
m := make(map[interface{}]interface{})
err = yaml.Unmarshal([]byte(data), &m)
for k, v := range m {
// Trying to explore the data here
fmt.Println("k:", k, "v:", v)
}
的输出
fmt.Printf("--- m:\n%v\n\n", m)
如下所示
map[steps:map[execute:[map[concurrent:false goals:clean install mvn:1.9.3] map[concurrent:false goals:dependency-check:check mvn:1.9.3]]]]
我的尝试
for k, v := range m {
fmt.Println("k:", k, "v:", v)
}