I'm creating a document generator from YAML input in Go. It needs to specify which line of the YAML file each item/node is generated from. Is there a way to achieve it in Go?
For example here's a YAML file
- key1: item 1
key2: item 2
- key1: another item 1
key2: another item 2
and I'd like to see the following
[
{'__line__': 1, 'key1': 'item 1', 'key2': 'item 2'},
{'__line__': 3, 'key1': 'another item 1', 'key2': 'another item 2'},
]
I see a similar question answered for Python Parsing YAML, return with line number but I'm missing how to make use of https://pkg.go.dev/gopkg.in/yaml.v3