【发布时间】:2021-06-06 01:30:35
【问题描述】:
我正在从 Go 中的 YAML 输入创建一个文档生成器。它需要指定每个项目/节点是从 YAML 文件的哪一行生成的。有没有办法在 Go 中实现它?
例如这里是一个 YAML 文件
- key1: item 1
key2: item 2
- key1: another item 1
key2: another item 2
我想看看以下内容
[
{'__line__': 1, 'key1': 'item 1', 'key2': 'item 2'},
{'__line__': 3, 'key1': 'another item 1', 'key2': 'another item 2'},
]
我看到 Python Parsing YAML, return with line number 的类似问题得到了回答,但我不知道如何使用 https://pkg.go.dev/gopkg.in/yaml.v3
【问题讨论】: