I'm trying to convert some Python code to Golang, and I'm having some difficulty figuring out how to load dynamic yaml data, which I thought was pretty basic. So far, all of the approaches I have found mention creating a Struct and mapping values, but this won't be possible since the data I'll be receiving will be different every time it's read.
This isn't the real data (which will actually be returned from an API), but as an example yaml file:
[ ~]$ cat /tmp/example.yaml
Massachusetts:
cities:
- name: 'Boston'
area_code: 617
- name: 'Springfield'
- name: 'Worcester'
Virginia:
cities:
- name: 'Richmond'
- name: 'Arlington'
landmarks:
- 'The Pentagon'
- 'National Airport'
- 'Arlington National Cemetary'
presidents:
- 'George Washington'
- 'Thomas Jefferson'
- 'James Madison'
- 'James Monroe'
- 'William Henry Harrison'
- 'John Tyler'
Missouri:
rivers:
- 'Missouri River'
- 'Mississippi'
- 'Arkansas River'
- 'White River'
And reading and manipulating it in Python is simple:
#!/usr/bin/python
import yaml
with open('/tmp/example.yaml', 'r') as fh:
data = yaml.load(fh)
print yaml.dump(data, default_flow_style=False)
As I'm new to Go, does anyone know which technique I should use / documentation I should look for that will do what this Python code does?