我有一个 yaml 文件,当前写为:
resource:
File:
containment_path:
- File
- File::Value
Default:
containment_path:
- Default
- Default::Echo
- Default[main]
Exec:
containment_path:
- Stage
- Exec::File
- Exec[File]
我使用结构来获取containment_path:
type Yaml struct {
ContainmentPath []string `yaml:"containment_path"`
}
我想超越遏制路径的范围,以获取containment_path中的第二个值:文件::值,默认::回声,执行::文件
我做这个代码:
for _, v := range m.ContainmentPath {
spew.Dump("Value ContainmentPath:", m.ContainmentPath)
spew.Dump("Value v[1]:", v[1])
value = v[1]
}
当我运行它时,我得到这个遏制路径:
(string) (len=8) "Value ContainmentPath:"
([]string) (len=2 cap=2) {
(string) (len=4) "File",
(string) (len=11) "File::Value"
}
(string) (len=8) "Value ContainmentPath:"
([]string) (len=3 cap=3) {
(string) (len=7) "Default",
(string) (len=13) "Default::Echo",
(string) (len=13) "Default[main]"
}
(string) (len=8) "Value ContainmentPath:"
([]string) (len=3 cap=3) {
(string) (len=5) "Stage",
(string) (len=10) "Exec::File",
(string) (len=10) "Exec[File]"
}
当我运行它时,我得到了v[1]的这个:
(string) (len=11) "Value v[1]:"
(uint8) 114
(string) (len=11) "Value v[1]:"
(uint8) 105
(string) (len=11) "Value v[1]:"
(uint8) 116
我想得到v[1]的值: 文件::值, 默认::回声, 执行::文件
我如何在Go中执行此操作?
谢谢
慕神8447489
相关分类