【发布时间】:2017-01-27 00:38:05
【问题描述】:
解析此类 yaml 文件时出现问题。使用"yaml.v2"
info: "abc"
data:
source: http://intra
destination: /tmp
run:
- id: "A1"
exe: "run.a1"
output: "output.A1"
- id: "A2"
exe: "run.a2"
output: "output.A2"
我想获取 YAML 文件的所有值,所以我有一个像这样的基本结构
type Config struct {
Info string
Data struct {
Source string `yaml:"source"`
Destination string `yaml:"destination"`
}
}
这行得通
但是,我不确定如何设置“运行”结构。额外的层让我感到困惑。
type Run struct {
...
}
【问题讨论】:
-
您的 yaml 文件示例无效,使用 Ruby 的 YAML 解析器会导致错误。你想像
{"run":[{"id":"A1","exe":"run.a1","output":"output.A1"},{"id":"A2",...}]}这样的 JSON 格式吗? -
固定原始问题